Friday, 17 November 2017

Introduction to Deep Learning

Introduction

In this class we will introduce the topic of Deep Learning, a rapidly growing segment of Artificial Intelligence. Deep Learning is increasingly being used to deliver near-human level accuracy in image classification, voice recognition, natural language processing, and more. In this class we will cover the basics of Deep Learning through some live examples, we will introduce the three major Deep Learning software frameworks and demonstrate why Deep Learning excels when run on GPUs.
This introductory class is intended to serve as a first introduction to the concept of Deep Learning and a live tour of the major software frameworks. There is some complex looking code presented, but it is not necessary to understand this code to complete the class. There are some times where you will be waiting a couple of minutes for the Deep Learning algorithms to run - feel free to use this time to explore the code.
By the end of this class you will hopefully be excited by the potential applications of Deep Learning and have a better idea of which of the frameworks you may want to learn more about in one of our upcoming follow-on classes.

What is Deep Learning?

Deep Learning (DL) is a branch of artificial intelligence research that is attempting to develop the techniques that will allow computers to learn complex perception tasks such as seeing and hearing at human levels of performance. Recent advances in DL have yielded startling performance gains in fields such as computer vision, speech recognition and natural language understanding. DL is already in use today to understand data and user inputs in technologies such as virtual personal assistants and online image search. DL is an active area of ongoing research where it is envisaged that human level perception of unstructured data will enable technologies such as self-driving cars and truly intelligent machines.
DL attempts to use large volumes of unstructured data, such as images and audio clips, to learn hierarchical models which capture the complex structure in the data and then use these models to predict properties of previously unseen data. For example, DL has proven extremely successful at learning hierarchical models of the visual features and concepts represented in handheld camera images and then using those models to automatically label previously unseen images with the objects present in them.
The models learned through DL are biologically inspired artificial neural networks (ANNs). An ANN is an interconnected group of nodes, akin to the vast network of neurons in a brain. In the image below, each circular node represents an artificial neuron and an arrow represents a connection from the output of one neuron to the input of another. Input data is fed into the red nodes, and dependent on the weights on the connections between nodes, causes varying levels of activation of the subsequent hidden and output nodes. In our example above the input nodes would be connected to image pixels and the output nodes would have a one-to-one correspondence with the possible object classes; the job of the hidden nodes is to learn the complex function which maps pixels to object labels.
Figure 3: Fully-connected Artificial Neural Network with one hidden layer
For the advanced reader, the activation of a neuron is just a function of a variable which is the weighted sum of the inputs. For basic neural networks the function is a sigmoid function. The idea is that if the weighted sum of the inputs exceeds a threshold value, the neuron gives a positive output.
For ANNs to be effective in difficult perception tasks, such as object labelling in images, these networks usually have many stacked layers of artificial neurons each with many neurons in the layer. It is these many wide layers that lead to these networks being labelled Deep Neural Networks (DNNs).
One particular class of DNN which has shown great capability in visual perception tasks is called the Convolutional Neural Network (CNN). CNNs have a structure which loosely resembles the structure the human visual cortex where lower levels of the model hierarchy are focused on small and local visual details, such as oriented line segments, which aggregate together into higher levels of the model which correspond to complex human concepts, such as faces and animals.
Figure 4: Deep Neural Networks learn a hierarchical model of the input data in which the layers correspond to increasingly complex real-world concepts. The number of parameters in a network is a function of the number of neurons in the network and the architecture of the network connectivity.
The Imagenet Challenge is an annual competition where competitors are provided with 1.2 million natural images from the internet which are labelled with the objects that appear in those images using 1000 different class labels. Competitors must create a model using this data which will then be tested against a further 100,000 images to see how accurately the model can identify and localize objects within them. Over the past few years CNN based approaches have come to dominate the competition with accuracy in the object identification task recently exceeding 95% - which is comparable with human performance in labelling the objects in the test dataset.
The mathematics that underpins DL training is predominantly linear matrix algebra. Computation of this type of mathematics is highly parallelizable making it a perfect fit for acceleration using GPUs. Training a DNN that can be competitive in the Imagenet challenge is computationally very intensive and would take weeks, months or even years of computation on a CPU based system. Through massive parallelization, GPUs can reduce this training time to days or even hours. Now almost all entrants into the Imagenet Challenge use GPUs, sometimes many of them, to train CNNs with billions of trainable parameters. The graph below shows how significant recent improvements in accuracy in the Imagenet challenge correlate with the explosion in the use of GPUs for training DNN entries.
Figure 5: The introduction of GPU accelerated Deep Learning into the ImageNet challenge began a period of unprecedented performance improvements.
GPUs are not only far more computationally efficient for training DNNs - they are also far more cost effective at scale. In 2013 Google built it's "Google Brain" - a 1000 server, 16,000 core CPU based cluster for training a state-of-the-art DNN for image understanding. It cost an estimated $5,000,000 to build. Shortly afterwards a team from the Stanford AI Lab showed that using 3 GPU accelerated servers with 12 GPUs per server - a total of 18,432 cores - they could train the same DNN and achieve the same performance. Their system cost approximately $33,000 - 150th of the hardware cost and energy usage (Wired Article).
Figure 6: GPUs are the most cost effective and size and power efficient means for training large Deep Neural Networks.

Saturday, 26 December 2015

Error shooting - PHP Warning: socket_bind(): unable to bind address [98]: Address already in use

problem:
-------------------------------------------------------------------------------------------------------------------

The problem occurs when you try to run you file(I am running a php client listen file) on server side,
this issue keep returning even after killing the process

PHP Warning:  socket_bind(): unable to bind address [98]: Address already in use 

for example: after running
# TOP
in server, find the process you want to stop, then
# kill $PID
then check the process, it was gone, in ideal situation. Okay, you won't found this process now, but when you try to run this file in you server, the error still exist.

So here is the solution:
--------------------------------------------------------------------------------------------------------------------

That error means there's something already listening on that port you're trying to listen on.
To find the culprit, use:
# netstat -tulpn
Then, after you made very sure you want to kill it, kill it, with either
# kill $PID
or, if that doesn't work, use the crowbar:
# kill -9 $PID


(replace $PID with the process id you want to kill)
#TIP: this is really useful to use netstat cammanf line to check current processes instead of top command line#

Monday, 14 December 2015

laravel5 php artisan migrate error


Problem:
----------------------------------------------------------------------------------------------------------------------
[PDOException] occurs when i try to running php artisan migrate in laravel5

looks like here:
MacBook-Pro:laravel5-project user$ php artisan migrate:refresh --seed


                                                    
  [PDOException]                                    
  SQLSTATE[HY000] [2002] No such file or directory  

Solution:
-----------------------------------------------------------------------------------------------------------------------
change host name in .env file
from:
DB_HOST=local host
to:
DB_HOST=127.0.0.1

It should be success when you try to run php artisan migrate again.

Thursday, 19 March 2015

An idea about create your own links anywhere, any message type

Here is my idea:

I wanna build a tool which is able to set your own links anywhere you want. It can be when you browse on BBC website, come across a special phrase, then you search on google, find the meaning for that, and you want to give it a remark so that review it next time when you see it.

Not just text from website, it can be any message type, like pictures, videos, even a song which type is mp3, you can still build a link for that.

So, this is something like bookmark, but it's much more power and useful than former one.

I hope anyone who is special interesting in my idea and able to develop this tool with me.

Moore Zhang

Saturday, 28 February 2015

HTTP Error 403.14 - Forbidden

HTTP Error 403.14 - Forbidden

The Web server is configured to not list the contents of this directory.


Most likely causes:

  • A default document is not configured for the requested URL, and directory browsing is not enabled on the server.

Things you can try:

  • If you do not want to enable directory browsing, ensure that a default document is configured and that the file exists.
  • Enable directory browsing.
    1. Go to the IIS Express install directory.
    2. Run /section:system.webServer/directoryBrowse appcmd set config / enabled: true to enable Directory browsing at the Server Level.  
    3. Run appcmd set config ["SITE_NAME"] /section:system.webServer/directoryBrowse / enabled: true to enable Level Directory browsing at the site.  
  • Verify that the configuration/system.webServer/directoryBrowse@enabled attribute is set to true in the site or application configuration file.

More Information:

This error occurs when a document is not specified in the URL, no default document is specified for the Web site or application, and directory listing is not enabled for the Web site or application. This setting may be disabled on purpose to secure the contents of the server.


Soluton: site.Master cannot be open, create a new form.aspx to use the master page!

Tuesday, 9 December 2014

Composite Primary Key using JPA and Hibernate

File: Customer.java


import java.io.Serializable;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import org.hibernate.validator.constraints.NotEmpty;

@Entity
public class Customer implements Serializable{
      
       @EmbeddedId
       @NotEmpty
       private CustomerId id;
       //Getter Setter for CustomerId
       public CustomerId getId() {
              return id;
       }
       public void setId(CustomerId id) {
              this.id = id;
       }
      
       private String customerBookItem;
       private String customerBookTime;
       //Getter Setter
       public String getCustomerBookItem() {
              return customerBookItem;
       }
       public void setCustomerBookItem(String customerBookItem) {
              this.customerBookItem = customerBookItem;
       }
       public String getCustomerBookTime() {
              return customerBookTime;
       }
       public void setCustomerBookTime(String customerBookTime) {
              this.customerBookTime = customerBookTime;
       }
      
      

}



File: CustomerId.java



import javax.persistence.Embeddable;
import java.io.Serializable;

@Embeddable
public class CustomerId implements Serializable{
      
       @NotEmpty
       private String customerBirthday;
       @NotEmpty
       private String customerName;
      
       //Constructor is necessary
       //default constructor
       public CustomerId() {
              super();
              // TODO Auto-generated constructor stub
       }
      
       //Constructor with attributes
       public CustomerId(String customerBirthday, String customerName) {
              super();
              this.customerBirthday = customerBirthday;
              this.customerName = customerName;
       }
      
       public String getCustomerBirthday() {
              return customerBirthday;
       }
       public void setCustomerBirthday(String customerBirthday) {
              this.customerBirthday = customerBirthday;
       }
       public String getCustomerName() {
              return customerName;
       }
       public void setCustomerName(String customerName) {
              this.customerName = customerName;
       }
      
}

Wednesday, 22 October 2014

多线程

进程与线程
多进程:在操作系统中能(同时)运行多个任务(程序)
多线程(multiple thread):在同一应用中有多个顺序流(同时)执行

线程lifecycle
线程类

//使用线程的方法一:继承Thread类
class FirstThread extends Thread(){
    //编写Run方法
    public void run(){
        for(int i = 0; i < 100; i++){
            System.out.println("");
        } 
    }
}

class Test{
    public static void main(String args[]){
        //生成线程类对象
        FirstThread ft = new FirstThread();
        //启动线程 ,使用start()方法,继承于Thread class
        //ft.run(); 单线程,不能这样写
        ft.start();//多线程
    }
}
Test class里有三个线程,将两个,一个是ft对象代表的线程,一个是Main()线程,(还有一个垃圾回收线程),CPU资源的分配是随机的。

//使用线程的方法二:接口Runnable
class runnableImp1 implements Runnable{
    public void run(){
        for(int i = 0; i < 100; i++){
        System.out.println("...");
        }
    }
}

class Test{
    public static void main(String args[]){
    //生成一个Runnable接口实现类的对象
    RunnableImpl ri = new RunnableImpl();
    //生成一个Thread对象,并将Runnable接口实现类的对象作为参数
    //传递给该Thread对象
    Thread t = new Thread();
    //通知Thread对象,执行start方法
    t.start();
    }
}

Java只支持单继承,推荐使用Runnable接口类

线程的简单控制方法
 - 中断线程
    Thread.sleep()
    Thread.yield()
 - 设置线程的优先级(1 - 10)
    getPriority()
    setPriority() by default, 优先级为5
优先级越大,执行的概率越大。

线程访问安全性
class MyThread implements Runnable{
    int i = 100;
    public void run(){
        while(true){
            //同步代码块
            synchroized(this){
                System.out.println(Thread.currentThread().getName() + i);
                i--;
                Thread.yield();
                if(i < 0){
                    break;
                }
            }
        }
    }
}

class Test{
    public static void main(String args[]){
        MyThread myThread = new MyThread();
        //生成两个Thread对象,共用同一个线程体
        Thread t1 = new Thread(myThread);
        Thread t2 = new Thread(myThread);
        //每一个线程都有名字,可以通过Thread对象setName()设置线程名字,也可以使用getName()获取线程的名子。
        t1.setName("线程a");
        t2.setName("线程b");
 
        t1.start();
        t2.start();
    }
}

多线程访问同一份资源,会出现多线程错误。解决方法:使用同步锁synchronized(this)

深入synchronized关键字
同步代码块(锁住对象)与同步方法作用类似,区别是同步代码块直接指定对象,同步方法也是指this。