A Practical Introduction to Deep Learning with Caffe

视觉特征-提取器:FPN:Feature Pyramid Net(特征金字塔) 【用于检测不同尺度的目标】【高分辨率特征图⬌低层次⬌语义弱】【用于替代“特征化图像金字塔”】【2016-12】 特征金字塔是识别系统中的基本组成部分,用于检测不同尺度的对象。但近年来的深度学习对象检测器避免使用金字塔表示,部分原因是其计算和内存开销较大。本文利用深度卷积网络固有的多尺度金字塔层级结构,以极少的额外成本构建特征金字塔。我们开发了一种具有横向连接的自顶向下架构,用于在所有尺度上构建高层语义特征图。该架构称为特征金字塔网络(Feature Pyramid Network,FPN),作为通用特征提取器,在多个应用中表现出显著改进。 阅读详情

A Practical Introduction to Deep Learning with Caffe 

Deep learning is the new big trend in machine learning. It had many recent successes in computer vision, automatic speech recognition and natural language processing.

The goal of this blog post is to give you a hands-on introduction to deep learning. To do this, we will build a Cat/Dog image classifier using a deep learning algorithm called convolutional neural network (CNN) and aKaggle dataset.

This post is divided into 2 main parts. The first part covers some core concepts behind deep learning, while the second part is structured in a hands-on tutorial format.

In the first part of the hands-on tutorial (section 4), we will build a Cat/Dog image classifier using a convolutional neural network from scratch. In the second part of the tutorial (section 5), we will cover an advanced technique for training convolutional neural networks called transfer learning. We will use some Python code and a popular open source deep learning framework called Caffe to build the classifier. Our classifier will be able to achieve a classification accuracy of 97%.

By the end of this post, you will understand how convolutional neural networks work, and you will get familiar with the steps and the code for building these networks.

The source code for this tutorial can be found in this github repository.

1. Problem Definition

In this tutorial, we will be using a dataset from Kaggle. The dataset is comprised of 25,000 images of dogs and cats.

Our goal is to build a machine learning algorithm capable of detecting the correct animal (cat or dog) in new unseen images.

In Machine learning, this type of problems is called classification.

Alt Text

2. Classification using Traditional Machine Learning vs. Deep Learning

Classification using a machine learning algorithm has 2 phases:

  • Training phase: In this phase, we train a machine learning algorithm using a dataset comprised of the images and their corresponding labels.
  • Prediction phase: In this phase, we utilize the trained model to predict labels of unseen images.

The training phase for an image classification problem has 2 main steps:

  1. Feature Extraction: In this phase, we utilize domain knowledge to extract new features that will be used by the machine learning algorithm. HoG and SIFT are examples of features used in image classification.

  2. Model Training: In this phase, we utilize a clean dataset composed of the images' features and the corresponding labels to train the machine learning model.

In the predicition phase, we apply the same feature extraction process to the new images and we pass the features to the trained machine learning algorithm to predict the label.

Alt Text

The main difference between traditional machine learning and deep learning algorithms is in the feature engineering. In traditional machine learning algorithms, we need to hand-craft the features. By contrast, in deep learning algorithms feature engineering is done automatically by the algorithm. Feature engineering is difficult, time-consuming and requires domain expertise. The promise of deep learning is more accurate machine learning algorithms compared to traditional machine learning with less or no feature engineering.

Alt Text

3. A Crash Course in Deep Learning

Deep learning refers to a class of artificial neural networks (ANNs) composed of many processing layers. ANNs existed for many decades, but attempts at training deep architectures of ANNs failed until Geoffrey Hinton's breakthrough work of the mid-2000s. In addition to algorithmic innovations, the increase in computing capabilities using GPUs and the collection of larger datasets are all factors that helped in the recent surge of deep learning.

3.1. Artificial Neural Networks (ANNs)

Artificial neural networks (ANNs) are a family of machine learning models inspired by biological neural networks.

Artificial Neural Networks vs. Biological Neural Networks

Biological Neurons are the core components of the human brain. A neuron consists of a cell body, dendrites, and an axon. It processes and transmit information to other neurons by emitting electrical signals. Each neuron receives input signals from its dendrites and produces output signals along its axon. The axon branches out and connects via synapses to dendrites of other neurons.

A basic model for how the neurons work goes as follows: Each synapse has a strength that is learnable and control the strength of influence of one neuron on another. The dendrites carry the signals to the target neuron's body where they get summed. If the final sum is above a certain threshold, the neuron get fired, sending a spike along its axon.[1]

Artificial neurons are inspired by biological neurons, and try to formulate the model explained above in a computational form. An artificial neuron has a finite number of inputs with weights associated to them, and an activation function (also called transfer function). The output of the neuron is the result of the activation function applied to the weighted sum of inputs. Artificial neurons are connected with each others to form artificial neural networks.

Alt Text

Feedforward Neural Networks

Feedforward Neural Networks are the simplest form of Artificial Neural Networks.

These networks have 3 types of layers: Input layer, hidden layer and output layer. In these networks, data moves from the input layer through the hidden nodes (if any) and to the output nodes.

Below is an example of a fully-connected feedforward neural network with 2 hidden layers. "Fully-connected" means that each node is connected to all the nodes in the next layer.

Note that, the number of hidden layers and their size are the only free parameters. The larger and deeper the hidden layers, the more complex patterns we can model in theory.

Alt Text

Activation Functions

Activation functions transform the weighted sum of inputs that goes into the artificial neurons. These functions should be non-linear to encode complex patterns of the data. The most popular activation functions are Sigmoid, Tanh and ReLU. ReLU is the most popular activation function in deep neural networks.

Alt Text

Training Artificial Neural Networks

The goal of the training phase is to learn the network's weights. We need 2 elements to train an artificial neural network:

  • Training data: In the case of image classification, the training data is composed of images and the corresponding labels.
  • Loss function: A function that measures the inaccuracy of predictions.

Once we have the 2 elements above, we train the ANN using an algorithm called backpropagation together with gradient descent (or one of its derivatives). For a detailed explanation of backpropagation, I recommend thisarticle.

3.2. Convolutional Neural Networks (CNNs or ConvNets)

Convolutional neural networks are a special type of feed-forward networks. These models are designed to emulate the behaviour of a visual cortex. CNNs perform very well on visual recognition tasks. CNNs have special layers called convolutional layers and pooling layers that allow the network to encode certain images properties.

Alt Text

Convolution Layer

This layer consists of a set of learnable filters that we slide over the image spatially, computing dot products between the entries of the filter and the input image. The filters should extend to the full depth of the input image. For example, if we want to apply a filter of size 5x5 to a colored image of size 32x32, then the filter should have depth 3 (5x5x3) to cover all 3 color channels (Red, Green, Blue) of the image. These filters will activate when they see same specific structure in the images.

Alt Text

Pooling Layer

Pooling is a form of non-linear down-sampling. The goal of the pooling layer is to progressively reduce the spatial size of the representation to reduce the amount of parameters and computation in the network, and hence to also control overfitting. There are several functions to implement pooling among which max pooling is the most common one. Pooling is often applied with filters of size 2x2 applied with a stride of 2 at every depth slice. A pooling layer of size 2x2 with stride of 2 shrinks the input image to a 1/4 of its original size. [2]

Alt Text

Convolutional Neural Networks Architecture

The simplest architecture of a convolutional neural networks starts with an input layer (images) followed by a sequence of convolutional layers and pooling layers, and ends with fully-connected layers. The convolutional layers are usually followed by one layer of ReLU activation functions.

The convolutional, pooling and ReLU layers act as learnable features extractors, while the fully connected layers acts as a machine learning classifier. Furthermore, the early layers of the network encode generic patterns of the images, while later layers encode the details patterns of the images.

Note that only the convolutional layers and fully-connected layers have weights. These weights are learned in the training phase.

Alt Text

4. Building a Cat/Dog Classifier using a Convolutional Neural Network

In this section, we will implement a cat/dog classifier using a convolutional neural network. We will use a dataset from Kaggle's Dogs vs. Cats competition. To implement the convolutional neural network, we will use a deep learning framework called Caffe and some Python code.

4.1 Getting Dogs & Cats Data

First, we need to download 2 datasets from the competition page: train.zip and test1.zip. The train.zip file contains labeled cats and dogs images that we will use to train the network. The test1.zip file contains unlabeled images that we will classify to either dog or cat using the trained model. We will upload our predictions to Kaggle to get the score of our prediction model.

4.2 Machine Setup

To train convolutional neural networks, we need a machine with a powerful GPU.

In this tutorial, I used one AWS EC2 instance of type g2.2xlarge. This instance has a high-performance NVIDIA GPU with 1,536 CUDA cores and 4GB of video memory, 15GB of RAM and 8 vCPUs. The machine costs $0.65/hour.

If you're not familiar with AWS, this guide will help you set up an AWS EC2 instance.

Please note, that the AMI recommended in the guide is no longer available. I prepared a new AMI (ami-64d31209) with all the necessary software installed. I also created a guide for installing Caffe and Anaconda on an AWS EC2 instance or an Ubuntu machine with GPU.

After setting up an AWS instance, we connect to it and clone the github repository that contains the necessary Python code and Caffe configuration files for the tutorial. From your terminal, execute the following command.

git clone https://github.com/adilmoujahid/deeplearning-cats-dogs-tutorial.git

Next, we create an input folder for storing the training and test images.

cd deeplearning-cats-dogs-tutorial
mkdir input

4.3 Caffe Overview

Caffe is a deep learning framework developed by the Berkeley Vision and Learning Center (BVLC). It is written in C++ and has Python and Matlab bindings.

There are 4 steps in training a CNN using Caffe:

  • Step 1 - Data preparation: In this step, we clean the images and store them in a format that can be used by Caffe. We will write a Python script that will handle both image pre-processing and storage.
  • Step 2 - Model definition: In this step, we choose a CNN architecture and we define its parameters in a configuration file with extension .prototxt.
  • Step 3 - Solver definition: The solver is responsible for model optimization. We define the solver parameters in a configuration file with extension .prototxt.
  • Step 4 - Model training: We train the model by executing one Caffe command from the terminal. After training the model, we will get the trained model in a file with extension .caffemodel.

After the training phase, we will use the .caffemodel trained model to make predictions of new unseen data. We will write a Python script to this.

4.4 Data Preparation

We start by copying the train.zip and test1.zip (that we downloaded to our local machine) to the input folder in the AWS instance. We can do this using the scp command from a MAC or linux machine. If you're running Windows, you can use a program such as Winscp. After copying the data, we unzip the files by executing the following commands:

unzip ~/deeplearning-cats-dogs-tutorial/input/train.zip
unzip ~/deeplearning-cats-dogs-tutorial/input/test1.zip
rm ~/deeplearning-cats-dogs-tutorial/input/*.zip

Next, we run create_lmdb.py.

cd ~/deeplearning-cats-dogs-tutorial/code
python create_lmdb.py

create_lmdb.py script does the following:

  • Run histogram equalization on all training images. Histogram equalization is a technique for adjusting the contrast of images.
  • Resize all training images to a 227x227 format.
  • Divide the training data into 2 sets: One for training (5/6 of images) and the other for validation (1/6 of images). The training set is used to train the model, and the validation set is used to calculate the accuracy of the model.
  • Store the training and validation in 2 LMDB databases. train_lmdb for training the model and validation_lmbd for model evaluation.

Below is the explanation of the most important parts of the code.

def transform_img(img, img_width=IMAGE_WIDTH, img_height=IMAGE_HEIGHT):

    #Histogram Equalization
    img[:, :, 0] = cv2.equalizeHist(img[:, :, 0])
    img[:, :, 1] = cv2.equalizeHist(img[:, :, 1])
    img[:, :, 2] = cv2.equalizeHist(img[:, :, 2])

    #Image Resizing
    img = cv2.resize(img, (img_width, img_height), interpolation = cv2.INTER_CUBIC)

    return img

transform_img takes a colored images as input, does the histogram equalization of the 3 color channels and resize the image.

Alt Text

def make_datum(img, label):

    return caffe_pb2.Datum(
        channels=3,
        width=IMAGE_WIDTH,
        height=IMAGE_HEIGHT,
        label=label,
        data=np.rollaxis(img, 2).tostring())

make_datum takes an image and its label and return a Datum object that contains the image and its label.

in_db = lmdb.open(train_lmdb, map_size=int(1e12))
with in_db.begin(write=True) as in_txn:
    for in_idx, img_path in enumerate(train_data):
        if in_idx %  6 == 0:
            continue
        img = cv2.imread(img_path, cv2.IMREAD_COLOR)
        img = transform_img(img, img_width=IMAGE_WIDTH, img_height=IMAGE_HEIGHT)
        if 'cat' in img_path:
            label = 0
        else:
            label = 1
        datum = make_datum(img, label)
        in_txn.put('{:0>5d}'.format(in_idx), datum.SerializeToString())
        print '{:0>5d}'.format(in_idx) + ':' + img_path
in_db.close()

The code above takes 5/6 of the training images, transforms and stores them in train_lmdb. The code for storing validation data follows the same structure.

Generating the mean image of training data

We execute the command below to generate the mean image of training data. We will substract the mean image from each input image to ensure every feature pixel has zero mean. This is a common preprocessing step in supervised machine learning.

/home/ubuntu/caffe/build/tools/compute_image_mean -backend=lmdb /home/ubuntu/deeplearning-cats-dogs-tutorial/input/train_lmdb /home/ubuntu/deeplearning-cats-dogs-tutorial/input/mean.binaryproto

4.4 Model Definition

After deciding on the CNN architecture, we need to define its parameters in a .prototxt train_val file. Caffe comes with a few popular CNN models such as Alexnet and GoogleNet. In this tutorial, we will use thebvlc_reference_caffenet model which is a replication of AlexNet with a few modifications. Below is a copy of the train_val file that we call caffenet_train_val_1.prototxt. If you clone the tutorial git repository as explained above, you should have the same file under deeplearning-cats-dogs-tutorial/caffe_models/caffe_model_1/.

We need to make the modifications below to the original bvlc_reference_caffenet prototxt file:

  • Change the path for input data and mean image: Lines 24, 40 and 51.
  • Change the number of outputs from 1000 to 2: Line 373. The original bvlc_reference_caffenet was designed for a classification problem with 1000 classes.
  name: "CaffeNet"
  layer {
  name: "data"
  type: "Data"
  top: "data"
  top: "label"
  include {
  phase: TRAIN
  }
  transform_param {
  mirror: true
  crop_size: 227
  mean_file: "/home/ubuntu/cats-dogs-tutorial/input/mean.binaryproto"
  }
  # mean pixel / channel-wise mean instead of mean image
  # transform_param {
  # crop_size: 227
  # mean_value: 104
  # mean_value: 117
  # mean_value: 123
  # mirror: true
  # }
  data_param {
  source: "/home/ubuntu/cats-dogs-tutorial/input/train_lmdb"
  batch_size: 256
  backend: LMDB
  }
  }
  layer {
  name: "data"
  type: "Data"
  top: "data"
  top: "label"
  include {
  phase: TEST
  }
  transform_param {
  mirror: false
  crop_size: 227
  mean_file: "/home/ubuntu/cats-dogs-tutorial/input/mean.binaryproto"
  }
  # mean pixel / channel-wise mean instead of mean image
  # transform_param {
  # crop_size: 227
  # mean_value: 104
  # mean_value: 117
  # mean_value: 123
  # mirror: true
  # }
  data_param {
  source: "/home/ubuntu/cats-dogs-tutorial/input/validation_lmdb"
  batch_size: 50
  backend: LMDB
  }
  }
  layer {
  name: "conv1"
  type: "Convolution"
  bottom: "data"
  top: "conv1"
  param {
  lr_mult: 1
  decay_mult: 1
  }
  param {
  lr_mult: 2
  decay_mult: 0
  }
  convolution_param {
  num_output: 96
  kernel_size: 11
  stride: 4
  weight_filler {
  type: "gaussian"
  std: 0.01
  }
  bias_filler {
  type: "constant"
  value: 0
  }
  }
  }
  layer {
  name: "relu1"
  type: "ReLU"
  bottom: "conv1"
  top: "conv1"
  }
  layer {
  name: "pool1"
  type: "Pooling"
  bottom: "conv1"
  top: "pool1"
  pooling_param {
  pool: MAX
  kernel_size: 3
  stride: 2
  }
  }
  layer {
  name: "norm1"
  type: "LRN"
  bottom: "pool1"
  top: "norm1"
  lrn_param {
  local_size: 5
  alpha: 0.0001
  beta: 0.75
  }
  }
  layer {
  name: "conv2"
  type: "Convolution"
  bottom: "norm1"
  top: "conv2"
  param {
  lr_mult: 1
  decay_mult: 1
  }
  param {
  lr_mult: 2
  decay_mult: 0
  }
  convolution_param {
  num_output: 256
  pad: 2
  kernel_size: 5
  group: 2
  weight_filler {
  type: "gaussian"
  std: 0.01
  }
  bias_filler {
  type: "constant"
  value: 1
  }
  }
  }
  layer {
  name: "relu2"
  type: "ReLU"
  bottom: "conv2"
  top: "conv2"
  }
  layer {
  name: "pool2"
  type: "Pooling"
  bottom: "conv2"
  top: "pool2"
  pooling_param {
  pool: MAX
  kernel_size: 3
  stride: 2
  }
  }
  layer {
  name: "norm2"
  type: "LRN"
  bottom: "pool2"
  top: "norm2"
  lrn_param {
  local_size: 5
  alpha: 0.0001
  beta: 0.75
  }
  }
  layer {
  name: "conv3"
  type: "Convolution"
  bottom: "norm2"
  top: "conv3"
  param {
  lr_mult: 1
  decay_mult: 1
  }
  param {
  lr_mult: 2
  decay_mult: 0
  }
  convolution_param {
  num_output: 384
  pad: 1
  kernel_size: 3
  weight_filler {
  type: "gaussian"
  std: 0.01
  }
  bias_filler {
  type: "constant"
  value: 0
  }
  }
  }
  layer {
  name: "relu3"
  type: "ReLU"
  bottom: "conv3"
  top: "conv3"
  }
  layer {
  name: "conv4"
  type: "Convolution"
  bottom: "conv3"
  top: "conv4"
  param {
  lr_mult: 1
  decay_mult: 1
  }
  param {
  lr_mult: 2
  decay_mult: 0
  }
  convolution_param {
  num_output: 384
  pad: 1
  kernel_size: 3
  group: 2
  weight_filler {
  type: "gaussian"
  std: 0.01
  }
  bias_filler {
  type: "constant"
  value: 1
  }
  }
  }
  layer {
  name: "relu4"
  type: "ReLU"
  bottom: "conv4"
  top: "conv4"
  }
  layer {
  name: "conv5"
  type: "Convolution"
  bottom: "conv4"
  top: "conv5"
  param {
  lr_mult: 1
  decay_mult: 1
  }
  param {
  lr_mult: 2
  decay_mult: 0
  }
  convolution_param {
  num_output: 256
  pad: 1
  kernel_size: 3
  group: 2
  weight_filler {
  type: "gaussian"
  std: 0.01
  }
  bias_filler {
  type: "constant"
  value: 1
  }
  }
  }
  layer {
  name: "relu5"
  type: "ReLU"
  bottom: "conv5"
  top: "conv5"
  }
  layer {
  name: "pool5"
  type: "Pooling"
  bottom: "conv5"
  top: "pool5"
  pooling_param {
  pool: MAX
  kernel_size: 3
  stride: 2
  }
  }
  layer {
  name: "fc6"
  type: "InnerProduct"
  bottom: "pool5"
  top: "fc6"
  param {
  lr_mult: 1
  decay_mult: 1
  }
  param {
  lr_mult: 2
  decay_mult: 0
  }
  inner_product_param {
  num_output: 4096
  weight_filler {
  type: "gaussian"
  std: 0.005
  }
  bias_filler {
  type: "constant"
  value: 1
  }
  }
  }
  layer {
  name: "relu6"
  type: "ReLU"
  bottom: "fc6"
  top: "fc6"
  }
  layer {
  name: "drop6"
  type: "Dropout"
  bottom: "fc6"
  top: "fc6"
  dropout_param {
  dropout_ratio: 0.5
  }
  }
  layer {
  name: "fc7"
  type: "InnerProduct"
  bottom: "fc6"
  top: "fc7"
  param {
  lr_mult: 1
  decay_mult: 1
  }
  param {
  lr_mult: 2
  decay_mult: 0
  }
  inner_product_param {
  num_output: 4096
  weight_filler {
  type: "gaussian"
  std: 0.005
  }
  bias_filler {
  type: "constant"
  value: 1
  }
  }
  }
  layer {
  name: "relu7"
  type: "ReLU"
  bottom: "fc7"
  top: "fc7"
  }
  layer {
  name: "drop7"
  type: "Dropout"
  bottom: "fc7"
  top: "fc7"
  dropout_param {
  dropout_ratio: 0.5
  }
  }
  layer {
  name: "fc8"
  type: "InnerProduct"
  bottom: "fc7"
  top: "fc8"
  param {
  lr_mult: 1
  decay_mult: 1
  }
  param {
  lr_mult: 2
  decay_mult: 0
  }
  inner_product_param {
  num_output: 2
  weight_filler {
  type: "gaussian"
  std: 0.01
  }
  bias_filler {
  type: "constant"
  value: 0
  }
  }
  }
  layer {
  name: "accuracy"
  type: "Accuracy"
  bottom: "fc8"
  bottom: "label"
  top: "accuracy"
  include {
  phase: TEST
  }
  }
  layer {
  name: "loss"
  type: "SoftmaxWithLoss"
  bottom: "fc8"
  bottom: "label"
  top: "loss"
  }

We can print the model architecture by executing the command below. The model architecture image will be stored under deeplearning-cats-dogs-tutorial/caffe_models/caffe_model_1/caffe_model_1.png

python /home/ubuntu/caffe/python/draw_net.py /home/ubuntu/deeplearning-cats-dogs-tutorial/caffe_models/caffe_model_1/caffenet_train_val_1.prototxt /home/ubuntu/deeplearning-cats-dogs-tutorial/caffe_models/caffe_model_1/caffe_model_1.png

Alt Text

4.5 Solver Definition

The solver is responsible for model optimization. We define the solver's parameters in a .prototxt file. You can find our solver under deeplearning-cats-dogs-tutorial/caffe_models/caffe_model_1/ with name solver_1.prototxt. Below is a copy of the same.

This solver computes the accuracy of the model using the validation set every 1000 iterations. The optimization process will run for a maximum of 40000 iterations and will take a snapshot of the trained model every 5000 iterations.

base_lr, lr_policy, gamma, momentum and weight_decay are hyperparameters that we need to tune to get a good convergence of the model.

I chose lr_policy: "step" with stepsize: 2500, base_lr: 0.001 and gamma: 0.1. In this configuration, we will start with a learning rate of 0.001, and we will drop the learning rate by a factor of ten every 2500 iterations.

There are different strategies for the optimization process. For a detailed explanation, I recommend Caffe's solver documentation.

  net: "/home/ubuntu/cats-dogs-tutorial/caffe_models/caffe_model_1/caffenet_train_val_1.prototxt"
  test_iter: 1000
  test_interval: 1000
  base_lr: 0.001
  lr_policy: "step"
  gamma: 0.1
  stepsize: 2500
  display: 50
  max_iter: 40000
  momentum: 0.9
  weight_decay: 0.0005
  snapshot: 5000
  snapshot_prefix: "/home/ubuntu/cats-dogs-tutorial/caffe_models/caffe_model_1/caffe_model_1"
  solver_mode: GPU
view raw solver_1.prototxt hosted with ❤ by  GitHub

4.6 Model Training

After defining the model and the solver, we can start training the model by executing the command below:

/home/ubuntu/caffe/build/tools/caffe train --solver /home/ubuntu/deeplearning-cats-dogs-tutorial/caffe_models/caffe_model_1/solver_1.prototxt 2>&1 | tee /home/ubuntu/deeplearning-cats-dogs-tutorial/caffe_models/caffe_model_1/model_1_train.log

The training logs will be stored under deeplearning-cats-dogs-tutorial/caffe_models/caffe_model_1/model_1_train.log.

During the training process, we need to monitor the loss and the model accuracy. We can stop the process at anytime by pressing Ctrl+c. Caffe will take a snapshot of the trained model every 5000 iterations, and store them under caffe_model_1 folder.

The snapshots have .caffemodel extension. For example, 10000 iterations snapshot will be called:caffe_model_1_iter_10000.caffemodel.

Plotting the learning curve

A learning curve is a plot of the training and test losses as a function of the number of iterations. These plots are very useful to visualize the train/validation losses and validation accuracy.

We can see from the learning curve that the model achieved a validation accuracy of 90%, and it stopped improving after 3000 iterations.

python /home/ubuntu/deeplearning-cats-dogs-tutorial/caffe_models/code/plot_learning_curve.py /home/ubuntu/deeplearning-cats-dogs-tutorial/caffe_models/caffe_models/caffe_model_1/model_1_train.log /home/ubuntu/deeplearning-cats-dogs-tutorial/caffe_models/caffe_models/caffe_model_1/caffe_model_1_learning_curve.png

Alt Text

4.7 Prediction on New Data

Now that we have a trained model, we can use it to make predictions on new unseen data (images from test1). The Python code for making the predictions is make_predictions_1.py and it's stored underdeeplearning-cats-dogs-tutorial/code. The code needs 4 files to run:

  • Test images: We will use test1 images.
  • Mean image: The mean image that we computed in section 4.4.
  • Model architecture file: We'll call this file caffenet_deploy_1.prototxt. It's stored underdeeplearning-cats-dogs-tutorial/caffe_models/caffe_model_1. It's structured in a similar way to caffenet_train_val_1.prototxt, but with a few modifications. We need to delete the data layers, add an input layer and change the last layer type from SoftmaxWithLoss to Softmax.
  • Trained model weights: This is the file that we computed in the training phase. We will usecaffe_model_1_iter_10000.caffemodel.

To run the Python code, we need to execute the command below. The predictions will be stored underdeeplearning-cats-dogs-tutorial/caffe_models/caffe_model_1/submission_model_1.csv.

cd /home/ubuntu/deeplearning-cats-dogs-tutorial/code
python make_predictions_1.py

Below is the explanation of the most important parts in the code.

#Read mean image
mean_blob = caffe_pb2.BlobProto()
with open('/home/ubuntu/deeplearning-cats-dogs-tutorial/input/mean.binaryproto') as f:
    mean_blob.ParseFromString(f.read())
mean_array = np.asarray(mean_blob.data, dtype=np.float32).reshape(
    (mean_blob.channels, mean_blob.height, mean_blob.width))


#Read model architecture and trained model's weights
net = caffe.Net('/home/ubuntu/deeplearning-cats-dogs-tutorial/caffe_models/caffe_model_1/caffenet_deploy_1.prototxt',
                '/home/ubuntu/deeplearning-cats-dogs-tutorial/caffe_models/caffe_model_1/caffe_model_1_iter_10000.caffemodel',
                caffe.TEST)

#Define image transformers
transformer = caffe.io.Transformer({'data': net.blobs['data'].data.shape})
transformer.set_mean('data', mean_array)
transformer.set_transpose('data', (2,0,1))

The code above stores the mean image under mean_array, defines a model called net by reading the deploy file and the trained model, and defines the transformations that we need to apply to the test images.

img = cv2.imread(img_path, cv2.IMREAD_COLOR)
img = transform_img(img, img_width=IMAGE_WIDTH, img_height=IMAGE_HEIGHT)

net.blobs['data'].data[...] = transformer.preprocess('data', img)
out = net.forward()
pred_probas = out['prob']
print pred_probas.argmax()

The code above read an image, apply similar image processing steps to training phase, calculates each class' probability and prints the class with the largest probability (0 for cats, and 1 for dogs).

After submitting the predicitions to Kaggle, it give an accuracy of 0.89691.

Alt Text

5. Building a Cat/Dog Classifier using Transfer Learning

In this section, we will use a very practical and powerful technique called transfer learning for building our cat/dog classifier.

5.1 What is Transfer Learning?

Convolutional neural networks require large datasets and a lot of computional time to train. Some networks could take up to 2-3 weeks across multiple GPUs to train. Transfer learning is a very useful technique that tries to address both problems. Instead of training the network from scratch, transfer learning utilizes a trained model on a different dataset, and adapts it to the problem that we're trying to solve.

There are 2 strategies for transfer learning:

  • Utilize the trained model as a fixed feature extractor: In this strategy, we remove the last fully connected layer from the trained model, we freeze the weights of the remaining layers, and we train a machine learning classifier on the output of the remaining layers.
  • Fine-tune the trained model: In this strategy, we fine tune the trained model on the new dataset by continuing the backpropagation. We can either fine-tune the whole network or freeze some of its layers.

For a detailed explanation of transfer learning, I recommend reading these notes.

5.2 Training the Cat/Dog Classifier using Transfer Learning

Caffe comes with a repository that is used by researchers and machine learning practitioners to share their trained models. This library is called Model Zoo.

We will utilize the trained bvlc_reference_caffenet as a starting point of building our cat/dog classifier using transfer learning. This model was trained on the ImageNet dataset which contains millions of images across 1000 categories.

We will use the fine-tuning strategy for training our model.

Download trained bvlc_reference_caffenet model

We can download the trained model by executing the command below.

cd /home/ubuntu/caffe/models/bvlc_reference_caffenet
wget http://dl.caffe.berkeleyvision.org/bvlc_reference_caffenet.caffemodel

Model Definition

The model and solver configuration files are stored under deeplearning-cats-dogs-tutorial/caffe_models/caffe_model_2. We need to make the following change to the original bvlc_reference_caffenet model configuration file.

  • Change the path for input data and mean image: Lines 24, 40 and 51.
  • Change the name of the last fully connected layer from fc8 to fc8-cats-dogs. Lines 360, 363, 387 and 397.
  • Change the number of outputs from 1000 to 2: Line 373. The original bvlc_reference_caffenet was designed for a classification problem with 1000 classes.

Note that if we keep a layer's name unchanged and we pass the trained model's weights to Caffe, it will pick its weights from the trained model. If we want to freeze a layer, we need to setup its lr_mult parameter to 0.

  name: "CaffeNet"
  layer {
  name: "data"
  type: "Data"
  top: "data"
  top: "label"
  include {
  phase: TRAIN
  }
  transform_param {
  mirror: true
  crop_size: 227
  mean_file: "/home/ubuntu/cats-dogs-tutorial/input/mean.binaryproto"
  }
  # mean pixel / channel-wise mean instead of mean image
  # transform_param {
  # crop_size: 227
  # mean_value: 104
  # mean_value: 117
  # mean_value: 123
  # mirror: true
  # }
  data_param {
  source: "/home/ubuntu/cats-dogs-tutorial/input/train_lmdb"
  batch_size: 256
  backend: LMDB
  }
  }
  layer {
  name: "data"
  type: "Data"
  top: "data"
  top: "label"
  include {
  phase: TEST
  }
  transform_param {
  mirror: false
  crop_size: 227
  mean_file: "/home/ubuntu/cats-dogs-tutorial/input/mean.binaryproto"
  }
  # mean pixel / channel-wise mean instead of mean image
  # transform_param {
  # crop_size: 227
  # mean_value: 104
  # mean_value: 117
  # mean_value: 123
  # mirror: true
  # }
  data_param {
  source: "/home/ubuntu/cats-dogs-tutorial/input/validation_lmdb"
  batch_size: 50
  backend: LMDB
  }
  }
  layer {
  name: "conv1"
  type: "Convolution"
  bottom: "data"
  top: "conv1"
  param {
  lr_mult: 1
  decay_mult: 1
  }
  param {
  lr_mult: 2
  decay_mult: 0
  }
  convolution_param {
  num_output: 96
  kernel_size: 11
  stride: 4
  weight_filler {
  type: "gaussian"
  std: 0.01
  }
  bias_filler {
  type: "constant"
  value: 0
  }
  }
  }
  layer {
  name: "relu1"
  type: "ReLU"
  bottom: "conv1"
  top: "conv1"
  }
  layer {
  name: "pool1"
  type: "Pooling"
  bottom: "conv1"
  top: "pool1"
  pooling_param {
  pool: MAX
  kernel_size: 3
  stride: 2
  }
  }
  layer {
  name: "norm1"
  type: "LRN"
  bottom: "pool1"
  top: "norm1"
  lrn_param {
  local_size: 5
  alpha: 0.0001
  beta: 0.75
  }
  }
  layer {
  name: "conv2"
  type: "Convolution"
  bottom: "norm1"
  top: "conv2"
  param {
  lr_mult: 1
  decay_mult: 1
  }
  param {
  lr_mult: 2
  decay_mult: 0
  }
  convolution_param {
  num_output: 256
  pad: 2
  kernel_size: 5
  group: 2
  weight_filler {
  type: "gaussian"
  std: 0.01
  }
  bias_filler {
  type: "constant"
  value: 1
  }
  }
  }
  layer {
  name: "relu2"
  type: "ReLU"
  bottom: "conv2"
  top: "conv2"
  }
  layer {
  name: "pool2"
  type: "Pooling"
  bottom: "conv2"
  top: "pool2"
  pooling_param {
  pool: MAX
  kernel_size: 3
  stride: 2
  }
  }
  layer {
  name: "norm2"
  type: "LRN"
  bottom: "pool2"
  top: "norm2"
  lrn_param {
  local_size: 5
  alpha: 0.0001
  beta: 0.75
  }
  }
  layer {
  name: "conv3"
  type: "Convolution"
  bottom: "norm2"
  top: "conv3"
  param {
  lr_mult: 1
  decay_mult: 1
  }
  param {
  lr_mult: 2
  decay_mult: 0
  }
  convolution_param {
  num_output: 384
  pad: 1
  kernel_size: 3
  weight_filler {
  type: "gaussian"
  std: 0.01
  }
  bias_filler {
  type: "constant"
  value: 0
  }
  }
  }
  layer {
  name: "relu3"
  type: "ReLU"
  bottom: "conv3"
  top: "conv3"
  }
  layer {
  name: "conv4"
  type: "Convolution"
  bottom: "conv3"
  top: "conv4"
  param {
  lr_mult: 1
  decay_mult: 1
  }
  param {
  lr_mult: 2
  decay_mult: 0
  }
  convolution_param {
  num_output: 384
  pad: 1
  kernel_size: 3
  group: 2
  weight_filler {
  type: "gaussian"
  std: 0.01
  }
  bias_filler {
  type: "constant"
  value: 1
  }
  }
  }
  layer {
  name: "relu4"
  type: "ReLU"
  bottom: "conv4"
  top: "conv4"
  }
  layer {
  name: "conv5"
  type: "Convolution"
  bottom: "conv4"
  top: "conv5"
  param {
  lr_mult: 1
  decay_mult: 1
  }
  param {
  lr_mult: 2
  decay_mult: 0
  }
  convolution_param {
  num_output: 256
  pad: 1
  kernel_size: 3
  group: 2
  weight_filler {
  type: "gaussian"
  std: 0.01
  }
  bias_filler {
  type: "constant"
  value: 1
  }
  }
  }
  layer {
  name: "relu5"
  type: "ReLU"
  bottom: "conv5"
  top: "conv5"
  }
  layer {
  name: "pool5"
  type: "Pooling"
  bottom: "conv5"
  top: "pool5"
  pooling_param {
  pool: MAX
  kernel_size: 3
  stride: 2
  }
  }
  layer {
  name: "fc6"
  type: "InnerProduct"
  bottom: "pool5"
  top: "fc6"
  param {
  lr_mult: 1
  decay_mult: 1
  }
  param {
  lr_mult: 2
  decay_mult: 0
  }
  inner_product_param {
  num_output: 4096
  weight_filler {
  type: "gaussian"
  std: 0.005
  }
  bias_filler {
  type: "constant"
  value: 1
  }
  }
  }
  layer {
  name: "relu6"
  type: "ReLU"
  bottom: "fc6"
  top: "fc6"
  }
  layer {
  name: "drop6"
  type: "Dropout"
  bottom: "fc6"
  top: "fc6"
  dropout_param {
  dropout_ratio: 0.5
  }
  }
  layer {
  name: "fc7"
  type: "InnerProduct"
  bottom: "fc6"
  top: "fc7"
  param {
  lr_mult: 1
  decay_mult: 1
  }
  param {
  lr_mult: 2
  decay_mult: 0
  }
  inner_product_param {
  num_output: 4096
  weight_filler {
  type: "gaussian"
  std: 0.005
  }
  bias_filler {
  type: "constant"
  value: 1
  }
  }
  }
  layer {
  name: "relu7"
  type: "ReLU"
  bottom: "fc7"
  top: "fc7"
  }
  layer {
  name: "drop7"
  type: "Dropout"
  bottom: "fc7"
  top: "fc7"
  dropout_param {
  dropout_ratio: 0.5
  }
  }
  layer {
  name: "fc8-cats-dogs"
  type: "InnerProduct"
  bottom: "fc7"
  top: "fc8-cats-dogs"
  param {
  lr_mult: 1
  decay_mult: 1
  }
  param {
  lr_mult: 2
  decay_mult: 0
  }
  inner_product_param {
  num_output: 2
  weight_filler {
  type: "gaussian"
  std: 0.01
  }
  bias_filler {
  type: "constant"
  value: 0
  }
  }
  }
  layer {
  name: "accuracy"
  type: "Accuracy"
  bottom: "fc8-cats-dogs"
  bottom: "label"
  top: "accuracy"
  include {
  phase: TEST
  }
  }
  layer {
  name: "loss"
  type: "SoftmaxWithLoss"
  bottom: "fc8-cats-dogs"
  bottom: "label"
  top: "loss"
  }

Solver Definition

We will use a similar solver to the one used in section 4.5.

  net: "/home/ubuntu/cats-dogs-tutorial/caffe_models/caffe_model_2/caffenet_train_val_2.prototxt"
  test_iter: 1000
  test_interval: 1000
  base_lr: 0.001
  lr_policy: "step"
  gamma: 0.1
  stepsize: 2500
  display: 50
  max_iter: 40000
  momentum: 0.9
  weight_decay: 0.0005
  snapshot: 5000
  snapshot_prefix: "/home/ubuntu/cats-dogs-tutorial/caffe_models/caffe_model_2/caffe_model_2"
  solver_mode: GPU
view raw solver_2.prototxt hosted with ❤ by  GitHub

Model Training with Transfer Learning

After defining the model and the solver, we can start training the model by executing the command below. Note that we can pass the trained model's weights by using the argument --weights.

/home/ubuntu/caffe/build/tools/caffe train --solver=/home/ubuntu/deeplearning-cats-dogs-tutorial/caffe_models/caffe_model_2/solver_2.prototxt --weights /home/ubuntu/caffe/models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel 2>&1 | tee /home/ubuntu/deeplearning-cats-dogs-tutorial/caffe_models/caffe_model_2/model_2_train.log

Plotting the Learning Curve

Similarly to the previous section, we can plot the learning curve by executing the command below. We can see from the learning curve that the model achieved an accuracy of ~97% after 1000 iterations only. This shows the power of transfer learning. We were able to get a higher accuracy with a smaller number of iterations.

python /home/ubuntu/deeplearning-cats-dogs-tutorial/code/plot_learning_curve.py /home/ubuntu/deeplearning-cats-dogs-tutorial/caffe_models/caffe_model_2/model_2_train.log /home/ubuntu/deeplearning-cats-dogs-tutorial/caffe_models/caffe_model_2/caffe_model_2_learning_curve.png

Alt Text

Prediction on New Data

Similary to section 4.7, we will generate predictions on the test data and upload the results to Kaggle to get the model accuracy. The code for making the predicitions is under deeplearning-cats-dogs-tutorial/code/make_predictions_2.py.

The model got an accuracy of 0.97154 which is better than the model that we trained from scratch.

Alt Text

Conclusion

In this blog post, we covered core concepts of deep learning and convolutional neural networks. We also learned how to build convolutional neural networks using Caffe and Python from scratch and using transfer learning. If you want to learn more about this topic, I highly recommend Stanford's "Convolutional Neural Networks for Visual Recognition" course.

References

  1. CS231n - Neural Networks Part 1: Setting up the Architecture
  2. Wikipedia - Convolutional Neural Network
  3. CS231n - Transfer Learning Notes
  4. A Step by Step Backpropagation Example
  5. CS231n Convolutional Neural Networks for Visual Recognition
Deep Learning(深度学习)代码/课程/学习资料整理【持续更新】 1. Deep Learning课程(由浅入深): Andrew Ng(吴恩达). Unsupervised Feature Learning and Deep Learning.在线地址,百度网盘下载. 主要侧重基本实验技巧和基本机器学习知识。吴立德.复旦大学深度学习课程.在线地址.百度网盘下载.讲解比较全面易懂,提纲挈领地讲到了各种基础知识。Oxford University(牛津大学) 阅读详情

相关推荐

深度学习之Encoder-Only原理与实战

【代码】深度学习之Encoder-Only原理与实战。

yumiwangzi30的博客 259

一步一步分析讲解神经网络基础-Feedforward Neural Network

A feedforward neural network is an artificial neural network wherein connections between the units do not form a cycle. As such, it is different from recurrent neural networks. The feedforward neural

凡难事必作于细的博客 2万+

Hands-On Transfer Learning with Python

Deep learning simplified by taking supervised, unsupervised, and reinforcement learning to the next level using the Python ecosystem Transfer learning is a machine learning (ML) technique where knowledge gained during training a set of problems can be used to solve other similar problems. The purpose of this book is two-fold; firstly, we focus on detailed coverage of deep learning (DL) and transfer learning, comparing and contrasting the two with easy-to-follow concepts and examples. The second area of focus is real-world examples and research problems using TensorFlow, Keras, and the Python ecosystem with hands-on examples. The book starts with the key essential concepts of ML and DL, followed by depiction and coverage of important DL architectures such as convolutional neural networks (CNNs), deep neural networks (DNNs), recurrent neural networks (RNNs), long short-term memory (LSTM), and capsule networks. Our focus then shifts to transfer learning concepts, such as model freezing, fine-tuning, pre-trained models including VGG, inception, ResNet, and how these systems perform better than DL models with practical examples. In the concluding chapters, we will focus on a multitude of real-world case studies and problems associated with areas such as computer vision, audio analysis and natural language processing (NLP). By the end of this book, you will be able to implement both DL and transfer learning principles in your own systems. What you will learn Set up your own DL environment with graphics processing unit (GPU) and Cloud support Delve into transfer learning principles with ML and DL models Explore various DL architectures, including CNN, LSTM, and capsule networks Learn about data and network representation and loss functions Get to grips with models and strategies in transfer learning Walk through potential challenges in building complex transfer learning models from scratch Explore real-world research problems related to computer vision and audio analysis Understand how transfer learning can be leveraged in NLP

读《Hands-On Transfer Learning with Python》初体验

读《Hands-On Transfer Learning with Python》初体验 最近由于工作原因及个人兴趣,对迁移学习兴趣盎然,很想深入了解该领域知识,偶得该领域最新力作,现分享阅读的一些心得和要点。 本书秉承一贯的传道授业顺序,从机器学习到深度学习再到迁移学习,建议对机器学习和深度学习有一定基础的同仁忽略前3章节。这里简要概括一下前3章的重点。 要了解迁移学习,首先要明白迁移学习在整个...

yingwei13mei的博客 1542

Hands-On_Reinforcement_Learning_with_Python

Hands On Reinforcement Learning with Python epub版本

Caffe Deep Learning Framework

Caffe Deep Learning Framework

mise bootstrap plugins 详解:管理 [bootstrap.plugins] 声明的包管理器插件

`mise bootstrap plugins` 是 mise 机器引导(bootstrap)工作流中专门用于管理包管理器插件(package manager plugins)的子命令组:`apply` 负责安装 `[bootstrap.plugins]` 中声明的插件,`status` 负责检查这些插件是否已经安装。读完本文,你将理解插件在 bootstrap 八阶段执行顺序中的位置、两条子命令

gitblog_00932的博客 375

迁移学习Python实战 Hands on transfer learning with Python

迁移学习Python实战 Hands on transfer learning with Python

读《Hands-On Transfer Learning with Python》小试锋芒之释放迁移学习的洪荒之力

本章的主要内容  The need for transfer learning  Building Convolutional Neural Network (CNN) models from scratch: Building a basic CNN model Improving our CNN model with regularization Improving our CNN mod...

yingwei13mei的博客 916

Deep Learning with Python A Hands-on Introduction 无水印pdf

Deep Learning with Python A Hands-on Introduction 英文无水印pdf pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除

LTC2990电池监控芯片I²C驱动开发与多通道同步采样实践

电池监控是嵌入式电源管理系统的核心环节,其本质依赖高精度模拟信号采集、数字转换与实时状态评估。LTC2990作为集成电压/电流/温度三合一的专用监控IC,通过真差分输入、内置基准和I²C数字接口,显著简化了SOC/SOH估算的硬件链路。其技术价值在于以单芯片替代传统ADC+运放+传感器组合,在宽压(2.7–36 V)、高共模(80 V)场景下保障工业级测量可靠性。典型应用于电动工具、车载BMS、UPS及便携式储能设备的电池健康监测子系统。本文聚焦LTC2990底层驱动实现,涵盖I²C时序约束、寄存器原子读写

weixin_42599558的博客 131

基于Caffe的深度学习实践

原网页引自:A Practical Introduction to Deep Learning with Caffe and Python 0.Introduction 这是一篇使用CNN进行分类的文章,数据集取自Kaggle-dog-cat。博客内容分为两部分:一、深度学习下的部分核心概念;二、实践教程。 实践教程也分为两部分:一、Section4部分,对数据从头学习CNN网络进行猫和

San_Junipero的博客 5748

Ubuntu20.04下运行VINS系列:VINS-Mono、VINS-Fusion和GVINS

安装好了VINS-Mono所需的ROS noetic、Eigen3.4.0、Ceres2.10和OpenCV4.2.0等。VINS-Mono是在ROS melodic以及Ceres1的环境下开发的,因此需要适配高版本的环境。

zardforever123的博客 2万+

DIY Deep Learning for Vision: A Tutorial With Caffe 报告笔记

目录 简介 要点记录 提问 总结 简介 报告时间是北京时间 12月14日 凌晨一点到两点,主讲人是 Caffe 团队的核心之一 Evan Shelhamer。第一次用 GoToMeeting 参加视频会议,效果真是不错。 报告后分享出了 视频 和 展示文件。另一讲座,cuDNN: Accelerating Convolutional Neural Networ

hdanbang的专栏 2266

华为 S2600T 存储 3 种网络端口(H4/H5/串口)用途解析与故障恢复实战

本文深度解析华为S2600T存储设备的三种关键网络端口(H4/H5/串口)的功能用途与故障恢复方法。通过详细的配置指南和实战案例,帮助管理员掌握管理接口(H4)的日常运维、维护接口(H5)的高级应用以及串口的应急操作,提升存储设备的可靠性和维护效率。

weixin_30899023的博客 336

西门子1200PLC编程实战:OB、FC、FB与DB的深度解析与应用技巧

本文深度解析西门子1200PLC编程中OB、FC、FB与DB四大核心功能块的应用技巧。通过工厂化比喻,阐明OB作为程序总调度、FC作为可重用函数、FB作为带记忆的智能设备以及DB作为数据仓库的角色与关系,并提供实战技巧,帮助工程师构建结构清晰、易于维护的高效PLC程序。

weixin_29280657的博客 440

Fast R-CNN

本文提出了一种用于目标检测的 Fast Region-based Convolutional Network 方法(Fast R-CNN)。Fast R-CNN 在先前工作的基础上,利用深度卷积网络高效地对候选区域进行分类。与先前工作相比,Fast R-CNN采用了多项创新,在提高训练和测试速度的同时,也提升了检测准确率。Fast R-CNN 对非常深的 VGG16 网络的训练速度比 R-CNN 快 9×,测试时快 213×,并且在 PASCAL VOC 2012 上取得了更高的 mAP。

u013250861的博客 159

1.3、云计算HCIP融合存储产品及部署

目标:描述Oceanstor V3系列存储产品系统组成及产品定位 描述Oceanstor V3硬件结构及软件架构 掌握存储系统与主机系统之间的连接 一、存储型号 低端型存储:Oceanstor 2200 2600 2800 V3/V5 终端型存储:Oceanstor 5300 5500 5600 5800 6800 V3/V5 高端型存储:Oceanstor 18000 二、Oceanstor V3系列存储系统定位 OceanStor V3系列存储系统是华为根据存储产品应用现状和存储

weixin_43666279的博客 1653

DB2的常见SQLCODE所表示负数的含义

SQL0007 SQLCODE -07 SQLSTATE 42601 Explanation: Character &1 (HEX &2) not valid in SQL statement. SQL0010 SQLCODE -10 SQLSTATE 42603 Explanation: String constant beginning &1 not...

libing398448548的专栏 5797

Win10+Anaconda环境下PaddleOCR保姆级安装指南(附常见报错解决方案)

本文提供Win10+Anaconda环境下PaddleOCR的保姆级安装指南,涵盖从环境配置到模型部署的全流程,特别针对常见报错提供解决方案。通过详细的步骤说明和实用技巧,帮助开发者快速完成PaddleOCR安装与测试,避免常见陷阱,提升OCR开发效率。

weixin_29096377的博客 375

SecureCRT串口连接保姆级教程:从驱动安装到波特率设置(附常见问题解决)

本文提供SecureCRT串口连接的保姆级教程,涵盖从USB转串口驱动安装、端口识别到波特率等核心参数设置的完整流程。针对连接失败、乱码、键盘输入无响应等高频问题,给出了深度排查与解决方案,帮助网络与嵌入式开发新手快速掌握串口调试技能。

weixin_29281941的博客 433

20 Transfer Learning

本身的数据比较少,但是我们却有其他的数据。例如我们做个猫狗识别器,我们会有下面的数据,这些数据没有和任务直接相关。例如共同的领域,但是是不同的任务目标,例如左下的实体的大象和老虎。又例如不同的领域,但是是相同的任务目标,右下的虚体的狗和猫。 还有很多这方面的例子,如图上面的。 迁移学习就例如上面的,把漫画家和研究生的全身做了对比。这样我们可以看漫画家来大概了解研究生。 现在我们把各个情况做...

Fly嘉 368

【Python计量】linearmodels面板数据回归(一)

我们以伍德里奇《计量经济学导论现代方法》的”第14章高级面板数据方法“的案例14.1为例,使用jtrain中的数据来进行固定效应估计。

mfsdmlove的博客 9277

【CS231n_2017】1-Introduction to CNN for Visual Recognition

  本专栏根据斯坦福大学2017年公开课CS231n的视频教程整理学习资料,做学习笔记。   首先简单介绍CS231n,又称Convolutional Neural Networks for Visual Recognition。   计算机视觉在我们的社会中无处不在,广泛应用于搜索、图像理解、应用程序、测绘、医药、无人驾驶飞机和自动驾驶汽车等领域。许多应用的核心是视觉识别任务,如图像分...

笔尖的博客 1424

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

caffe introduction & classification

caffe 介绍caffe是Berkely的深度学习框架,在流行的deep learning framework里属于使用人数很多的,github上的统计显示经常是使用量第一的 这里是官方地址,上面有介绍和安装的指南caffe的优点 Expression: models + optimizations are plaintext schemas, not code. Speed: f

GavinZhou的博客 1455

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

深度学习0:数学知识:正态分布1

步骤内容结果1引入e−x2e^{-x^2}e−x2钟形曲线2算它的面积I∫−∞∞e−x2dxI∫−∞∞​e−x2dx3平方变成二重积分I2I^2I24换极坐标简化计算5算出I2πI^2 = \piI2πIπIπ​6代入σ\sigmaσ和μ\muμ做变量替换得到σ2πσ2π​7除以它归一化得到正态分布公式2π2π​不是随便写的,它来自高斯积分∫−∞∞e−x2。

tellmewhoisi的博客 188

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

上一篇: 神经网络+深度学习+增强学习
下一篇: 运行caffe自带的两个简单例子
arag2009
博客等级 码龄16年 142粉丝 7原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值