2017/05/07

Note of Image Segmentation by Machine Learning

An awesome implementation of the image segmentation by CNN
https://github.com/torrvision/crfasrnn/blob/master/README.md
http://www.robots.ox.ac.uk/~szheng/CRFasRNN.html

The problem here is that the model is too big, 500M. 
I do not need the classification part. 

related work
https://github.com/shelhamer/fcn.berkeleyvision.org


It is possible to porting it to mobile device, somebody has done this: 
http://libccv.org/post/how-to-run-a-state-of-the-art-image-classifier-on-a-iphone/
https://github.com/liuliu/klaus

2017/03/01

Password-based Encryption

You should use a key derivation function, such as PBKDF2. A key derivation function takes a salt and a supplied user password, and produces a key that can be used with a cipher like AES.

To encrypt, you would prompt for a password, generate a random salt, and derive a key using the KDF. You would then use that key with AES in a suitable block cipher mode to encrypt the data, and store only the salt and the encrypted data (and whatever IV the cipher mode requires).

To decrypt, you would prompt for a password, load the salt from the file, and re-derive the key. You would then use that key to decrypt the file.

The purpose of the salt is to prevent precomputation optimisations from being applied to a dictionary attack. It is indeed possible to perform a bruteforce dictionary attack once the salt is known, but the KDF is designed to be slow enough to make this infeasible without precomputation.

Reference:
http://stackoverflow.com/questions/5040130/security-using-aes-with-salted-password-as-key

2017/02/12

Notes About Optimization of Machine Learning

Partial Derivative
In mathematics, a partial derivative of a function of several variables is its derivative with respect to one of those variables, with the others held constant (as opposed to the total derivative, in which all variables are allowed to vary). Partial derivatives are used in vector calculus and differential geometry.


Optimization Goal
The loss function lets us quantify the quality of any particular set of weights W. The goal of optimization is to find W that minimizes the loss function.


How to Optimize
Strategy #3: Following the Gradient

In one-dimensional functions, the slope is the instantaneous rate of change of the function at any point you might be interested in. The gradient is a generalization of slope for functions that don’t take a single number but a vector of numbers. Additionally, the gradient is just a vector of slopes (more commonly referred to as derivatives) for each dimension in the input space.  The mathematical expression for the derivative of a 1-D function with respect its input is:




When the functions of interest take a vector of numbers instead of a single number, we call the derivatives partial derivatives, and the gradient is simply the vector of partial derivatives in each dimension.

There are two ways to compute the gradient: A slow, approximate but easy way (numerical gradient), and a fast, exact but more error-prone way that requires calculus (analytic gradient)


Gradient Descent
Now that we can compute the gradient of the loss function, the procedure of repeatedly evaluating the gradient and then performing a parameter update is called Gradient Descent.


Mini-batch gradient descent
In large-scale applications (such as the ILSVRC challenge), the training data can have on order of millions of examples. Hence, it seems wasteful to compute the full loss function over the entire training set in order to perform only a single parameter update. A very common approach to addressing this challenge is to compute the gradient over batches of the training data. For example, in current state of the art ConvNets, a typical batch contains 256 examples from the entire training set of 1.2 million


Reference
http://cs231n.github.io/optimization-1/

2017/02/09

A Neuron In a Neural Net

This is an neural network


This a Neuron and Neuron Model





b: Bias
w: Weight
f: Activation function

Activation Function Example
- ReLU (Rectified linear unit)
- Leaky ReLU
- Sigmoid
- Tahn
-


2017/01/17

Complex scattering example

What code/data must be placed in a root region of a scatter file?

The initialization code/data from within the C library that does the copying from load to execution addresses must be placed in a root region (i.e. one which executes at its load address). This is because this code/data cannot itself be copied. This means that the scatter description file must have at least one root region that must contain:
  • The copying code from the library member called __main.o.
  • Sections named Region$$Table and ZISection$$Table which contain the addresses of the code/data to be copied. These sections are generated by the linker so they do not have a corresponding object file (so * must be used when placing these in a scatter file).
If these sections named Region$$Table and ZISection$$Table are not placed in a root region then the linker will report:
Error: L6202E: Section Region$$Table cannot be assigned to a non-root region.
Error: L6202E: Section ZISection$$Table cannot be assigned to a non-root region. 
In many cases this code/data may be placed in a root region by use of a wildcard *(+RO) that gathers all non-explicitly placed code/data. However in some circumstances, this wildcard may need to be placed in a non-root region, in which case a scatter file similar to the one below may be used.
Example scatter file for ADS and RVCT 2.0:
LOAD_FLASH 0x04000000 0x80000   ;start address and length
{
    EXEC_FLASH 0x04000000 0x80000
    {
        init.o (Init,+FIRST)    ; remap & init code
        __main.o (+RO)          ; copy code
        * (Region$$Table)       ; RO/RW addresses to copy
        * (ZISection$$Table)    ; ZI addresses to zero
    }
    EXEC_32bitRAM 0x0000 0x2000
    {
        vectors.o (Vect,+FIRST) ; vector table
        int_handler.o (+RO)     ; interrupt handler
    }
    EXEC_16bitRAM 0x2000 0x80000
    {
        * (+RO)                 ; ## all other RO areas ##
        * (+RW,+ZI)             ; program variables
    }
} 
For RVCT 2.1 and later, an alternative way is to specify these sections using InRoot$$Sections:
LOAD_FLASH 0x04000000 0x80000   ;start address and length
{
    EXEC_FLASH 0x04000000 0x80000
    {
        init.o (Init,+FIRST)    ; remap & init code
        * (InRoot$$Sections)    ; using InRoot$$Sections
    }
    ...
} 
An application's initial entry point must also be rooted. If the initial entry point is not in a root region, the link will fail with an error such as:
Error: L6203E: Entry point (0x08000000) lies within non-root region EXE_FLASH. 


Reference:
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0474g/BABEJHII.html

http://www.keil.com/support/man/docs/armlink/armlink_pge1362065974588.htm

http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.faqs/ka3552.html

2017/01/16

ARM Scatter File Explain

Bookmark below simple straight forward explaining
http://www.keil.com/support/man/docs/armlink/armlink_pge1362065973150.htm
Simple scatter-loaded memory map
7.1.6 Scatter-loading images with a simple memory map
For images with a simple memory map, you can specify the memory map using only linker command-line options, or with a scatter file.
The following figure shows a simple memory map:
Figure 7-1 Simple scatter-loaded memory map

Simple scatter-loaded memory map

Simple scatter-loaded memory map






The following example shows the corresponding scatter-loading description that loads the segments from the object file into memory:

LOAD_ROM 0x0000 0x8000       ; Name of load region (LOAD_ROM),
                             ; Start address for load region (0x0000),
                             ; Maximum size of load region (0x8000)
{
    EXEC_ROM 0x0000 0x8000   ; Name of first exec region (EXEC_ROM),
                             ; Start address for exec region (0x0000),
                             ; Maximum size of first exec region (0x8000)
    {
        * (+RO)              ; Place all code and RO data into
                             ; this exec region
    }
    SRAM 0x10000 0x6000      ; Name of second exec region (SRAM),
                             ; Start address of second exec region (0x10000),
                             ; Maximum size of second exec region (0x6000)
    {
        * (+RW, +ZI)         ; Place all RW and ZI data into
                             ; this exec region
    }
}

2016/11/20

PCIE Configuration & Enumeration

Configure Space Addressing
One of the major improvements the PCI Local Bus had over other I/O architectures was its configuration mechanism. In addition to the normal memory-mapped and I/O port spaces, each device function on the bus has a configuration space, which is 256 bytes long, addressable by knowing the eight-bit PCI bus, five-bit device, and three-bit function numbers for the device (commonly referred to as the BDF or B/D/F, as abbreviated from bus/device/function)


About Device ID and Vendor ID
The Device ID (DID) and Vendor ID (VID) registers identify the device (such as an IC), and are commonly called the PCI ID. The 16-bit vendor ID is allocated by the PCI-SIG. The 16-bit device ID is then assigned by the vendor. There is an ongoing project to collect all known Vendor and Device IDs. (See the external links below.)


Software Implementation
First method Addressing a device via Bus, Device, and Function (BDF) is also referred to as "addressing a device geographically."
  See arch/x86/pci/early.c in the Linux kernel code for an example of code that uses geographical addressing.
https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/arch/x86/pci/early.c?id=refs/tags/v3.12.7

The second method was created for PCI Express. It is called Enhanced Configuration Access Mechanism (ECAM). It extends device's configuration space to 4k, with the bottom 256 bytes overlapping the original (legacy) configuration space in PCI. The section of the addressable space is "stolen" so that the accesses from the CPU don't go to memory but rather reach a given device in the PCI Express fabric. During system initialization, firmware determines the base address for this “stolen” address region and communicates it to the root complex and to the operating system. This communication method is implementation-specific, and not defined in the PCI Express specification.


Enumeration
Since there is no direct method for the BIOS or operating system to determine which PCI slots have devices installed (nor which functions the device implements) the PCI bus(es) must be enumerated. Bus enumeration is performed by attempting to read the vendor register and device ID (VID/DID) register for each combination of bus number and device number at the device's function #0. Note that device number, different from DID, is merely a device's sequential number on that bus, moreover, after a new bridge a new bus number is defined and device enumeration restart by zero.

The process by which configuration software discovers the system topology and assigns
bus numbers and system resources.
On x86 PCIe hierarchy enumeration done by BIOS on hardware initialization state – all
registers configured before bootloader.
System software can re-assign enumeration according to enumeration rules.

Reference
https://en.wikipedia.org/wiki/PCI_configuration_space


Post Code on Blogger

Simplest way to post code to blogger for me: <pre style="background: #f0f0f0; border: 1px dashed #CCCCCC; color: black;overflow-x:...