如何用caffe解决线性回归解决什么问题问题

使用caffe的HDF5数据完成回归任务-爱编程
使用caffe的HDF5数据完成回归任务
&&& 一直在研究如何用caffe做行人检测问题,然而参考那些经典结构比如faster-rcnn等,都是自定义的caffe层来完成的检测任务。这些都要求对caffe框架有一定程度的了解。最近看到了如何用caffe完成回归的任务,就想把检测问题当成回归问题来解决。
&&& 我们把行人检测问题当成回归来看待,就需要限制检出目标的个数,因为我们的输出个数是固定的。所以,这里我假定每张图片最多检出的目标个数为2。即每个目标用4个值来表示其位置信息(中心位置坐标x,y。BBox的宽和高),则网络的最后输出是8个值。
制作HDF5数据
&&& 这里我们使用HDF5格式的数据来完成我们的回归任务,那么首先我们需要的是制作h5格式的数据。这里以VOC数据集为例。下面是制作HDF5格式数据的python代码。
import h5py
import caffe
import xml.etree.ElementTree as ET
import cv2
import time
import math
from os.path import join, exists
import numpy as np
def convert(size, box):
dw = 1./size[0]
dh = 1./size[1]
x = (box[0] + box[1])/2.0
y = (box[2] + box[3])/2.0
w = box[1] - box[0]
h = box[3] - box[2]
return (x,y,w,h)
def shuffle_in_unison_scary(a, b):
rng_state = np.random.get_state()
np.random.shuffle(a)
np.random.set_state(rng_state)
np.random.shuffle(b)
def processImage(imgs):
imgs = imgs.astype(np.float32)
for i, img in enumerate(imgs):
m = img.mean()
s = img.std()
imgs[i] = (img - m) / s
return imgs
TrainImgDir = 'F:/GenerateHDF5/trainImage'
TrainLabelDir = 'F:/GenerateHDF5/trainLabels'
TestImgDir = 'F:/GenerateHDF5/testImg'
TestLabelDir = 'F:/GenerateHDF5/testLabels'
InImg = []
InBBox = []
for rootDir,dirs,files in os.walk(TestLabelDir):
for file in files:
file_name = file.split('.')[0]
full_file_name = '%s%s'%(file_name,'.jpg')
full_file_dir = '%s/%s'%(TestImgDir,full_file_name)
Img = cv2.imread(full_file_dir,cv2.CV_LOAD_IMAGE_GRAYSCALE)
xml_file = open(&%s/%s&%(rootDir,file))
tree = ET.parse(xml_file)
root = tree.getroot()
size = root.find('size')
w = int(size.find('width').text)
h = int(size.find('height').text)
landmark = np.zeros(8)
for obj in root.iter('object'):
count = count + 1
if count == 3:
xmlbox = obj.find('bndbox')
b = (float(xmlbox.find('xmin').text), float(xmlbox.find('xmax').text), float(xmlbox.find('ymin').text), float(xmlbox.find('ymax').text))
bb = convert((w,h), b)
landmark[(count-1)*4+0]=bb[0]
landmark[(count-1)*4+1]=bb[1]
landmark[(count-1)*4+2]=bb[2]
landmark[(count-1)*4+3]=bb[3]
InBBox.append(landmark.reshape(8))
Img = cv2.resize(Img,(h,w))
InImg.append(Img.reshape((1,h,w)))
InImg, InBBox = np.asarray(InImg), np.asarray(InBBox)
InImg = processImage(InImg)
shuffle_in_unison_scary(InImg, InBBox)
outputDir = 'hdf5/'
HDF5_file_name = 'hdf5_test.h5'
if not os.path.exists(outputDir):
os.makedirs(outputDir)
output = join(outputDir,HDF5_file_name)
with h5py.File(output, 'w') as h5:
h5['data'] = InImg.astype(np.float32)
h5['labels'] = InBBox.astype(np.float32)
h5.close()
这里注意一点,所有的BBox数据都要做归一化操作,即所有坐标要除以图片对应的宽高。据说,这样做能使最后得到的结果更好。
制作好了HDF5数据后,注意每个H5文件大小不能超过2G(这是caffe的规定,如果一个文件超过2G,请分开制作多个)。然后建立一个TXT文件,文件里写上所有H5文件的绝对路径,比如我这里建立的文件是list_train.txt。然后我只有一个H5文件,即hdf5_train.h5。所以我的list_train.txt文件中的内容就是/home/XXX/caffe/model/hdf5/hdf5_train.h5
配置solver文件
接下来是caffe的solver文件,这个文件没有什么区别,
test_iter: 20
test_interval: 70
base_lr: 0.
display: 9
max_iter: 210000
lr_policy: &step&
gamma: 0.1
momentum: 0.9
weight_decay: 0.0001
stepsize: 700
snapshot: 500
snapshot_prefix: &snapshot&
solver_mode: GPU
net: &train_val.prototxt&
solver_type: SGD
配置train_val.prototxt文件
接下来是网络的train_val.prototxt文件。这是caffe的网络结构文件,我们这里以LeNet网络为例,我这里是这样的:
name: &LeNet&
name: &data&
type: &HDF5Data&
top: &data&
top: &labels&
phase: TRAIN
hdf5_data_param {
source: &list_train.txt&
batch_size: 50
name: &data&
type: &HDF5Data&
top: &data&
top: &labels&
phase: TEST
hdf5_data_param {
source: &list_test.txt&
batch_size: 50
name: &conv1&
type: &Convolution&
bottom: &scaled&
top: &conv1&
lr_mult: 1.0
lr_mult: 2.0
convolution_param {
num_output: 20
kernel_size: 5
weight_filler {
type: &xavier&
bias_filler {
type: &constant&
name: &pool1&
type: &Pooling&
bottom: &conv1&
top: &pool1&
pooling_param {
kernel_size: 2
name: &conv2&
type: &Convolution&
bottom: &pool1&
top: &conv2&
lr_mult: 1.0
lr_mult: 2.0
convolution_param {
num_output: 50
kernel_size: 5
weight_filler {
type: &xavier&
bias_filler {
type: &constant&
name: &pool2&
type: &Pooling&
bottom: &conv2&
top: &pool2&
pooling_param {
kernel_size: 2
name: &ip1&
type: &InnerProduct&
bottom: &pool2&
top: &ip1&
lr_mult: 1.0
lr_mult: 2.0
inner_product_param {
num_output: 500
weight_filler {
type: &xavier&
bias_filler {
type: &constant&
name: &relu1&
type: &ReLU&
bottom: &ip1&
top: &ip1&
name: &ip2&
type: &InnerProduct&
bottom: &ip1&
top: &ip2&
lr_mult: 1.0
lr_mult: 2.0
inner_product_param {
num_output: 8
weight_filler {
type: &xavier&
bias_filler {
type: &constant&
name: &error&
type: &EuclideanLoss&
bottom: &ip2&
bottom: &labels&
top: &error&
phase: TEST
name: &loss&
type: &EuclideanLoss&
bottom: &ip2&
bottom: &labels&
top: &loss&
phase: TRAIN
这里注意的是,最后的一层全连接层,输出的num_output应该是你label的维度,我这里是8。然后最后的loss计算,我使用的是欧氏距离的loss,也可以试着用其他类型的loss。
按照以上步骤配置好了,最后就是训练了。在控制台中输入以下指令来训练我们的数据:
./cafferoot/caffe/tools/caffe train --solver=solver.prototxt
可能是我数据源的问题,我的loss一开始非常大,然后一直降不下来。也有可能是LeNet本身网络性能就不好。关于网络的性能还需要另外再想办法提升。
版权所有 爱编程 (C) Copyright 2012. . All Rights Reserved.
闽ICP备号-3
微信扫一扫关注爱编程,每天为您推送一篇经典技术文章。1836人阅读
caffe(15)
虽然Caffe是设计给深度网络的,但它也可以表示“浅层”网络模型用于分类,例如逻辑回归。下面在合成数据上做简单的逻辑回归,生成并保存为HDF5,来向Caffe输入向量。模型完成后,添加层来提高准确率。Caffe完成的主要内容就是:定义模型,实验,应用。
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
os.chdir('..')
import sys
sys.path.insert(0, './python')
import caffe
import h5py
import shutil
import tempfile
import sklearn
import sklearn.datasets
import sklearn.linear_model
import pandas as pd
合成10,000个4向量的数据集,用于有2个有用特征和2个噪声特征的二值分类。
X, y = sklearn.datasets.make_classification(
n_samples=10000, n_features=4, n_redundant=0, n_informative=2,
n_clusters_per_class=2, hypercube=False, random_state=0
# Split into train and test
X, Xt, y, yt = sklearn.cross_validation.train_test_split(X, y)
# Visualize sample of the data
ind = np.random.permutation(X.shape[0])[:1000]
df = pd.DataFrame(X[ind])
_ = pd.scatter_matrix(df, figsize=(9, 9), diagonal='kde', marker='o', s=40, alpha=.4, c=y[ind])
用于学习scikit-learn逻辑回归的方法是随机梯度下降(SGD),下面检测分类器的准确性:
clf = sklearn.linear_model.SGDClassifier(
loss='log', n_iter=1000, penalty='l2', alpha=1e-3, class_weight='auto')
clf.fit(X, y)
yt_pred = clf.predict(Xt)
print('Accuracy: {:.3f}'.format(sklearn.metrics.accuracy_score(yt, yt_pred)))
Accuracy: 0.783
Accuracy: 0.783
Accuracy: 0.783
Accuracy: 0.783
1 loops, best of 3: 508 ms per loop
将这个数据集保存到HDF5中,方便Caffe载入:
dirname = os.path.abspath('./examples/hdf5_classification/data')
if not os.path.exists(dirname):
os.makedirs(dirname)
train_filename = os.path.join(dirname, 'train.h5')
test_filename = os.path.join(dirname, 'test.h5')
with h5py.File(train_filename, 'w') as f:
f['data'] = X
f['label'] = y.astype(np.float32)
with open(os.path.join(dirname, 'train.txt'), 'w') as f:
f.write(train_filename + '\n')
f.write(train_filename + '\n')
comp_kwargs = {'compression': 'gzip', 'compression_opts': 1}
with h5py.File(test_filename, 'w') as f:
f.create_dataset('data', data=Xt, **comp_kwargs)
f.create_dataset('label', data=yt.astype(np.float32), **comp_kwargs)
with open(os.path.join(dirname, 'test.txt'), 'w') as f:
f.write(test_filename + '\n')
通过Python网络规范来定义Caffe中的逻辑回归,如果不想手工编写protobuf模型的话这是一个好方法:
from caffe import layers as L
from caffe import params as P
def logreg(hdf5, batch_size):
n = caffe.NetSpec()
n.data, n.label = L.HDF5Data(batch_size=batch_size, source=hdf5, ntop=2)
n.ip1 = L.InnerProduct(n.data, num_output=2, weight_filler=dict(type='xavier'))
n.accuracy = L.Accuracy(n.ip1, n.label)
n.loss = L.SoftmaxWithLoss(n.ip1, n.label)
return n.to_proto()
with open('examples/hdf5_classification/logreg_auto_train.prototxt', 'w') as f:
f.write(str(logreg('examples/hdf5_classification/data/train.txt', 10)))
with open('examples/hdf5_classification/logreg_auto_test.prototxt', 'w') as f:
f.write(str(logreg('examples/hdf5_classification/data/test.txt', 10)))
现在开始学习与评估Python中的Caffe逻辑回归:
caffe.set_mode_cpu()
solver = caffe.get_solver('examples/hdf5_classification/solver.prototxt')
solver.solve()
accuracy = 0
batch_size = solver.test_nets[0].blobs['data'].num
test_iters = int(len(Xt) / batch_size)
for i in range(test_iters):
solver.test_nets[0].forward()
accuracy += solver.test_nets[0].blobs['accuracy'].data
accuracy /= test_iters
print("Accuracy: {:.3f}".format(accuracy))
Accuracy: 0.782
Accuracy: 0.782
Accuracy: 0.782
Accuracy: 0.782
1 loops, best of 3: 287 ms per loop
用命令行来运行,看一下具体的模型文件和求解过程:
!./build/tools/caffe train -solver examples/hdf5_classification/solver.prototxt
I0318 00:58:32.322571
caffe.cpp:117] Use CPU.
I0318 00:58:32.643163
caffe.cpp:121] Starting Optimization
I0318 00:58:32.643229
solver.cpp:32] Initializing solver from parameters:
train_net: "examples/hdf5_classification/logreg_auto_train.prototxt"
test_net: "examples/hdf5_classification/logreg_auto_test.prototxt"
test_iter: 250
test_interval: 1000
base_lr: 0.01
display: 1000
max_iter: 10000
lr_policy: "step"
gamma: 0.1
momentum: 0.9
weight_decay: 0.0005
stepsize: 5000
snapshot: 10000
snapshot_prefix: "examples/hdf5_classification/data/train"
solver_mode: CPU
I0318 00:58:32.643333
solver.cpp:61] Creating training net from train_net file: examples/hdf5_classification/logreg_auto_train.prototxt
I0318 00:58:32.643465
net.cpp:42] Initializing net from parameters:
phase: TRAIN
name: "data"
type: "HDF5Data"
top: "data"
top: "label"
hdf5_data_param {
source: "examples/hdf5_classification/data/train.txt"
batch_size: 10
name: "ip1"
type: "InnerProduct"
bottom: "data"
top: "ip1"
inner_product_param {
num_output: 2
weight_filler {
type: "xavier"
name: "accuracy"
type: "Accuracy"
bottom: "ip1"
bottom: "label"
top: "accuracy"
name: "loss"
type: "SoftmaxWithLoss"
bottom: "ip1"
bottom: "label"
top: "loss"
I0318 00:58:32.644197
layer_factory.hpp:74] Creating layer data
I0318 00:58:32.644219
net.cpp:84] Creating Layer data
I0318 00:58:32.644230
net.cpp:338] data -& data
I0318 00:58:32.644256
net.cpp:338] data -& label
I0318 00:58:32.644269
net.cpp:113] Setting up data
I0318 00:58:32.644278
hdf5_data_layer.cpp:66] Loading list of HDF5 filenames from: examples/hdf5_classification/data/train.txt
I0318 00:58:32.644327
hdf5_data_layer.cpp:80] Number of HDF5 files: 2
I0318 00:58:32.646458
net.cpp:120] Top shape: 10 4 (40)
I0318 00:58:32.646502
net.cpp:120] Top shape: 10 (10)
I0318 00:58:32.646518
layer_factory.hpp:74] Creating layer label_data_1_split
I0318 00:58:32.646538
net.cpp:84] Creating Layer label_data_1_split
I0318 00:58:32.646546
net.cpp:380] label_data_1_split &- label
I0318 00:58:32.646556
net.cpp:338] label_data_1_split -& label_data_1_split_0
I0318 00:58:32.646569
net.cpp:338] label_data_1_split -& label_data_1_split_1
I0318 00:58:32.646579
net.cpp:113] Setting up label_data_1_split
I0318 00:58:32.646586
net.cpp:120] Top shape: 10 (10)
I0318 00:58:32.646595
net.cpp:120] Top shape: 10 (10)
I0318 00:58:32.646601
layer_factory.hpp:74] Creating layer ip1
I0318 00:58:32.646615
net.cpp:84] Creating Layer ip1
I0318 00:58:32.646622
net.cpp:380] ip1 &- data
I0318 00:58:32.646664
net.cpp:338] ip1 -& ip1
I0318 00:58:32.646689
net.cpp:113] Setting up ip1
I0318 00:58:32.652330
net.cpp:120] Top shape: 10 2 (20)
I0318 00:58:32.652371
layer_factory.hpp:74] Creating layer ip1_ip1_0_split
I0318 00:58:32.652393
net.cpp:84] Creating Layer ip1_ip1_0_split
I0318 00:58:32.652407
net.cpp:380] ip1_ip1_0_split &- ip1
I0318 00:58:32.652421
net.cpp:338] ip1_ip1_0_split -& ip1_ip1_0_split_0
I0318 00:58:32.652467
net.cpp:338] ip1_ip1_0_split -& ip1_ip1_0_split_1
I0318 00:58:32.652480
net.cpp:113] Setting up ip1_ip1_0_split
I0318 00:58:32.652489
net.cpp:120] Top shape: 10 2 (20)
I0318 00:58:32.652498
net.cpp:120] Top shape: 10 2 (20)
I0318 00:58:32.652505
layer_factory.hpp:74] Creating layer accuracy
I0318 00:58:32.652521
net.cpp:84] Creating Layer accuracy
I0318 00:58:32.652534
net.cpp:380] accuracy &- ip1_ip1_0_split_0
I0318 00:58:32.652545
net.cpp:380] accuracy &- label_data_1_split_0
I0318 00:58:32.652562
net.cpp:338] accuracy -& accuracy
I0318 00:58:32.652577
net.cpp:113] Setting up accuracy
I0318 00:58:32.652590
net.cpp:120] Top shape: (1)
I0318 00:58:32.652642
layer_factory.hpp:74] Creating layer loss
I0318 00:58:32.652655
net.cpp:84] Creating Layer loss
I0318 00:58:32.652663
net.cpp:380] loss &- ip1_ip1_0_split_1
I0318 00:58:32.652672
net.cpp:380] loss &- label_data_1_split_1
I0318 00:58:32.652679
net.cpp:338] loss -& loss
I0318 00:58:32.652689
net.cpp:113] Setting up loss
I0318 00:58:32.652701
layer_factory.hpp:74] Creating layer loss
I0318 00:58:32.652716
net.cpp:120] Top shape: (1)
I0318 00:58:32.652724
net.cpp:122]
with loss weight 1
I0318 00:58:32.652740
net.cpp:167] loss needs backward computation.
I0318 00:58:32.652746
net.cpp:169] accuracy does not need backward computation.
I0318 00:58:32.652753
net.cpp:167] ip1_ip1_0_split needs backward computation.
I0318 00:58:32.652760
net.cpp:167] ip1 needs backward computation.
I0318 00:58:32.652786
net.cpp:169] label_data_1_split does not need backward computation.
I0318 00:58:32.652801
net.cpp:169] data does not need backward computation.
I0318 00:58:32.652808
net.cpp:205] This network produces output accuracy
I0318 00:58:32.652815
net.cpp:205] This network produces output loss
I0318 00:58:32.652825
net.cpp:447] Collecting Learning Rate and Weight Decay.
I0318 00:58:32.652833
net.cpp:217] Network initialization done.
I0318 00:58:32.652839
net.cpp:218] Memory required for data: 528
I0318 00:58:32.652964
solver.cpp:154] Creating test net (#0) specified by test_net file: examples/hdf5_classification/logreg_auto_test.prototxt
I0318 00:58:32.652986
net.cpp:42] Initializing net from parameters:
phase: TEST
name: "data"
type: "HDF5Data"
top: "data"
top: "label"
hdf5_data_param {
source: "examples/hdf5_classification/data/test.txt"
batch_size: 10
name: "ip1"
type: "InnerProduct"
bottom: "data"
top: "ip1"
inner_product_param {
num_output: 2
weight_filler {
type: "xavier"
name: "accuracy"
type: "Accuracy"
bottom: "ip1"
bottom: "label"
top: "accuracy"
name: "loss"
type: "SoftmaxWithLoss"
bottom: "ip1"
bottom: "label"
top: "loss"
I0318 00:58:32.653069
layer_factory.hpp:74] Creating layer data
I0318 00:58:32.653080
net.cpp:84] Creating Layer data
I0318 00:58:32.653090
net.cpp:338] data -& data
I0318 00:58:32.653128
net.cpp:338] data -& label
I0318 00:58:32.653146
net.cpp:113] Setting up data
I0318 00:58:32.653154
hdf5_data_layer.cpp:66] Loading list of HDF5 filenames from: examples/hdf5_classification/data/test.txt
I0318 00:58:32.653192
hdf5_data_layer.cpp:80] Number of HDF5 files: 1
I0318 00:58:32.654850
net.cpp:120] Top shape: 10 4 (40)
I0318 00:58:32.654897
net.cpp:120] Top shape: 10 (10)
I0318 00:58:32.654914
layer_factory.hpp:74] Creating layer label_data_1_split
I0318 00:58:32.654933
net.cpp:84] Creating Layer label_data_1_split
I0318 00:58:32.654943
net.cpp:380] label_data_1_split &- label
I0318 00:58:32.654953
net.cpp:338] label_data_1_split -& label_data_1_split_0
I0318 00:58:32.654966
net.cpp:338] label_data_1_split -& label_data_1_split_1
I0318 00:58:32.654976
net.cpp:113] Setting up label_data_1_split
I0318 00:58:32.654985
net.cpp:120] Top shape: 10 (10)
I0318 00:58:32.654992
net.cpp:120] Top shape: 10 (10)
I0318 00:58:32.655000
layer_factory.hpp:74] Creating layer ip1
I0318 00:58:32.655010
net.cpp:84] Creating Layer ip1
I0318 00:58:32.655017
net.cpp:380] ip1 &- data
I0318 00:58:32.655030
net.cpp:338] ip1 -& ip1
I0318 00:58:32.655041
net.cpp:113] Setting up ip1
I0318 00:58:32.655061
net.cpp:120] Top shape: 10 2 (20)
I0318 00:58:32.655072
layer_factory.hpp:74] Creating layer ip1_ip1_0_split
I0318 00:58:32.655148
net.cpp:84] Creating Layer ip1_ip1_0_split
I0318 00:58:32.655159
net.cpp:380] ip1_ip1_0_split &- ip1
I0318 00:58:32.655170
net.cpp:338] ip1_ip1_0_split -& ip1_ip1_0_split_0
I0318 00:58:32.655180
net.cpp:338] ip1_ip1_0_split -& ip1_ip1_0_split_1
I0318 00:58:32.655190
net.cpp:113] Setting up ip1_ip1_0_split
I0318 00:58:32.655199
net.cpp:120] Top shape: 10 2 (20)
I0318 00:58:32.655206
net.cpp:120] Top shape: 10 2 (20)
I0318 00:58:32.655213
layer_factory.hpp:74] Creating layer accuracy
I0318 00:58:32.655223
net.cpp:84] Creating Layer accuracy
I0318 00:58:32.655230
net.cpp:380] accuracy &- ip1_ip1_0_split_0
I0318 00:58:32.655237
net.cpp:380] accuracy &- label_data_1_split_0
I0318 00:58:32.655251
net.cpp:338] accuracy -& accuracy
I0318 00:58:32.655259
net.cpp:113] Setting up accuracy
I0318 00:58:32.655267
net.cpp:120] Top shape: (1)
I0318 00:58:32.655340
layer_factory.hpp:74] Creating layer loss
I0318 00:58:32.655354
net.cpp:84] Creating Layer loss
I0318 00:58:32.655361
net.cpp:380] loss &- ip1_ip1_0_split_1
I0318 00:58:32.655369
net.cpp:380] loss &- label_data_1_split_1
I0318 00:58:32.655378
net.cpp:338] loss -& loss
I0318 00:58:32.655388
net.cpp:113] Setting up loss
I0318 00:58:32.655397
layer_factory.hpp:74] Creating layer loss
I0318 00:58:32.655414
net.cpp:120] Top shape: (1)
I0318 00:58:32.655422
net.cpp:122]
with loss weight 1
I0318 00:58:32.655438
net.cpp:167] loss needs backward computation.
I0318 00:58:32.655446
net.cpp:169] accuracy does not need backward computation.
I0318 00:58:32.655455
net.cpp:167] ip1_ip1_0_split needs backward computation.
I0318 00:58:32.655462
net.cpp:167] ip1 needs backward computation.
I0318 00:58:32.655469
net.cpp:169] label_data_1_split does not need backward computation.
I0318 00:58:32.655477
net.cpp:169] data does not need backward computation.
I0318 00:58:32.655483
net.cpp:205] This network produces output accuracy
I0318 00:58:32.655489
net.cpp:205] This network produces output loss
I0318 00:58:32.655503
net.cpp:447] Collecting Learning Rate and Weight Decay.
I0318 00:58:32.655511
net.cpp:217] Network initialization done.
I0318 00:58:32.655517
net.cpp:218] Memory required for data: 528
I0318 00:58:32.655547
solver.cpp:42] Solver scaffolding done.
I0318 00:58:32.655567
solver.cpp:222] Solving
I0318 00:58:32.655575
solver.cpp:223] Learning Rate Policy: step
I0318 00:58:32.655583
solver.cpp:266] Iteration 0, Testing net (#0)
I0318 00:58:32.683643
solver.cpp:315]
Test net output #0: accuracy = 0.3736
I0318 00:58:32.683686
solver.cpp:315]
Test net output #1: loss = 1.00555 (* 1 = 1.00555 loss)
I0318 00:58:32.683846
solver.cpp:189] Iteration 0, loss = 0.869394
I0318 00:58:32.683861
solver.cpp:204]
Train net output #0: accuracy = 0.3
I0318 00:58:32.683871
solver.cpp:204]
Train net output #1: loss = 0.869394 (* 1 = 0.869394 loss)
I0318 00:58:32.683883
solver.cpp:464] Iteration 0, lr = 0.01
I0318 00:58:32.698721
solver.cpp:266] Iteration 1000, Testing net (#0)
I0318 00:58:32.701917
solver.cpp:315]
Test net output #0: accuracy = 0.7848
I0318 00:58:32.701961
solver.cpp:315]
Test net output #1: loss = 0.590972 (* 1 = 0.590972 loss)
I0318 00:58:32.702014
solver.cpp:189] Iteration 1000, loss = 0.54742
I0318 00:58:32.702029
solver.cpp:204]
Train net output #0: accuracy = 0.7
I0318 00:58:32.702041
solver.cpp:204]
Train net output #1: loss = 0.54742 (* 1 = 0.54742 loss)
I0318 00:58:32.702051
solver.cpp:464] Iteration 1000, lr = 0.01
I0318 00:58:32.718360
solver.cpp:266] Iteration 2000, Testing net (#0)
I0318 00:58:32.721529
solver.cpp:315]
Test net output #0: accuracy = 0.7696
I0318 00:58:32.721562
solver.cpp:315]
Test net output #1: loss = 0.593946 (* 1 = 0.593946 loss)
I0318 00:58:32.721593
solver.cpp:189] Iteration 2000, loss = 0.729569
I0318 00:58:32.721603
solver.cpp:204]
Train net output #0: accuracy = 0.5
I0318 00:58:32.721613
solver.cpp:204]
Train net output #1: loss = 0.729569 (* 1 = 0.729569 loss)
I0318 00:58:32.721622
solver.cpp:464] Iteration 2000, lr = 0.01
I0318 00:58:32.740182
solver.cpp:266] Iteration 3000, Testing net (#0)
I0318 00:58:32.743494
solver.cpp:315]
Test net output #0: accuracy = 0.77
I0318 00:58:32.743544
solver.cpp:315]
Test net output #1: loss = 0.591229 (* 1 = 0.591229 loss)
I0318 00:58:32.744209
solver.cpp:189] Iteration 3000, loss = 0.406097
I0318 00:58:32.744231
solver.cpp:204]
Train net output #0: accuracy = 0.8
I0318 00:58:32.744249
solver.cpp:204]
Train net output #1: loss = 0.406096 (* 1 = 0.406096 loss)
I0318 00:58:32.744266
solver.cpp:464] Iteration 3000, lr = 0.01
I0318 00:58:32.764135
solver.cpp:266] Iteration 4000, Testing net (#0)
I0318 00:58:32.769110
solver.cpp:315]
Test net output #0: accuracy = 0.7848
I0318 00:58:32.769170
solver.cpp:315]
Test net output #1: loss = 0.590972 (* 1 = 0.590972 loss)
I0318 00:58:32.769223
solver.cpp:189] Iteration 4000, loss = 0.54742
I0318 00:58:32.769242
solver.cpp:204]
Train net output #0: accuracy = 0.7
I0318 00:58:32.769255
solver.cpp:204]
Train net output #1: loss = 0.54742 (* 1 = 0.54742 loss)
I0318 00:58:32.769265
solver.cpp:464] Iteration 4000, lr = 0.01
I0318 00:58:32.785846
solver.cpp:266] Iteration 5000, Testing net (#0)
I0318 00:58:32.788722
solver.cpp:315]
Test net output #0: accuracy = 0.7696
I0318 00:58:32.788751
solver.cpp:315]
Test net output #1: loss = 0.593946 (* 1 = 0.593946 loss)
I0318 00:58:32.788811
solver.cpp:189] Iteration 5000, loss = 0.72957
I0318 00:58:32.788833
solver.cpp:204]
Train net output #0: accuracy = 0.5
I0318 00:58:32.788846
solver.cpp:204]
Train net output #1: loss = 0.729569 (* 1 = 0.729569 loss)
I0318 00:58:32.788856
solver.cpp:464] Iteration 5000, lr = 0.001
I0318 00:58:32.804762
solver.cpp:266] Iteration 6000, Testing net (#0)
I0318 00:58:32.808061
solver.cpp:315]
Test net output #0: accuracy = 0.7856
I0318 00:58:32.808112
solver.cpp:315]
Test net output #1: loss = 0.59028 (* 1 = 0.59028 loss)
I0318 00:58:32.808732
solver.cpp:189] Iteration 6000, loss = 0.415444
I0318 00:58:32.808753
solver.cpp:204]
Train net output #0: accuracy = 0.9
I0318 00:58:32.808773
solver.cpp:204]
Train net output #1: loss = 0.415444 (* 1 = 0.415444 loss)
I0318 00:58:32.808786
solver.cpp:464] Iteration 6000, lr = 0.001
I0318 00:58:32.827118
solver.cpp:266] Iteration 7000, Testing net (#0)
I0318 00:58:32.831614
solver.cpp:315]
Test net output #0: accuracy = 0.7848
I0318 00:58:32.831657
solver.cpp:315]
Test net output #1: loss = 0.589454 (* 1 = 0.589454 loss)
I0318 00:58:32.831707
solver.cpp:189] Iteration 7000, loss = 0.538038
I0318 00:58:32.831728
solver.cpp:204]
Train net output #0: accuracy = 0.8
I0318 00:58:32.831745
solver.cpp:204]
Train net output #1: loss = 0.538037 (* 1 = 0.538037 loss)
I0318 00:58:32.831759
solver.cpp:464] Iteration 7000, lr = 0.001
I0318 00:58:32.849634
solver.cpp:266] Iteration 8000, Testing net (#0)
I0318 00:58:32.852712
solver.cpp:315]
Test net output #0: accuracy = 0.7796
I0318 00:58:32.852748
solver.cpp:315]
Test net output #1: loss = 0.589365 (* 1 = 0.589365 loss)
I0318 00:58:32.852792
solver.cpp:189] Iteration 8000, loss = 0.684219
I0318 00:58:32.852840
solver.cpp:204]
Train net output #0: accuracy = 0.5
I0318 00:58:32.852852
solver.cpp:204]
Train net output #1: loss = 0.684219 (* 1 = 0.684219 loss)
I0318 00:58:32.852861
solver.cpp:464] Iteration 8000, lr = 0.001
I0318 00:58:32.868440
solver.cpp:266] Iteration 9000, Testing net (#0)
I0318 00:58:32.871438
solver.cpp:315]
Test net output #0: accuracy = 0.7816
I0318 00:58:32.871461
solver.cpp:315]
Test net output #1: loss = 0.589656 (* 1 = 0.589656 loss)
I0318 00:58:32.872109
solver.cpp:189] Iteration 9000, loss = 0.421879
I0318 00:58:32.872131
solver.cpp:204]
Train net output #0: accuracy = 0.9
I0318 00:58:32.872143
solver.cpp:204]
Train net output #1: loss = 0.421879 (* 1 = 0.421879 loss)
I0318 00:58:32.872153
solver.cpp:464] Iteration 9000, lr = 0.001
I0318 00:58:32.889981
solver.cpp:334] Snapshotting to examples/hdf5_classification/data/train_iter_10000.caffemodel
I0318 00:58:32.890224
solver.cpp:342] Snapshotting solver state to examples/hdf5_classification/data/train_iter_10000.solverstate
I0318 00:58:32.890362
solver.cpp:248] Iteration 10000, loss = 0.538933
I0318 00:58:32.890380
solver.cpp:266] Iteration 10000, Testing net (#0)
I0318 00:58:32.893728
solver.cpp:315]
Test net output #0: accuracy = 0.782
I0318 00:58:32.893757
solver.cpp:315]
Test net output #1: loss = 0.589366 (* 1 = 0.589366 loss)
I0318 00:58:32.893775
solver.cpp:253] Optimization Done.
I0318 00:58:32.893786
caffe.cpp:134] Optimization Done.
看一下上面的输出或者logreg_auto_train.prototxt,就会发现这个模型是简单的逻辑回归,可以通过引入输入权重和输出权重之间的非线性,使这个模型更好一点,变成两层的,把这个网络放在nonlinear_auto_train.prototxt中。新网络最终的准确率比逻辑回归要高:
from caffe import layers as L
from caffe import params as P
def nonlinear_net(hdf5, batch_size):
n = caffe.NetSpec()
n.data, n.label = L.HDF5Data(batch_size=batch_size, source=hdf5, ntop=2)
n.ip1 = L.InnerProduct(n.data, num_output=40, weight_filler=dict(type='xavier'))
n.relu1 = L.ReLU(n.ip1, in_place=True)
n.ip2 = L.InnerProduct(n.ip1, num_output=2, weight_filler=dict(type='xavier'))
n.accuracy = L.Accuracy(n.ip2, n.label)
n.loss = L.SoftmaxWithLoss(n.ip2, n.label)
return n.to_proto()
with open('examples/hdf5_classification/nonlinear_auto_train.prototxt', 'w') as f:
f.write(str(nonlinear_net('examples/hdf5_classification/data/train.txt', 10)))
with open('examples/hdf5_classification/nonlinear_auto_test.prototxt', 'w') as f:
f.write(str(nonlinear_net('examples/hdf5_classification/data/test.txt', 10)))
caffe.set_mode_cpu()
solver = caffe.get_solver('examples/hdf5_classification/nonlinear_solver.prototxt')
solver.solve()
accuracy = 0
batch_size = solver.test_nets[0].blobs['data'].num
test_iters = int(len(Xt) / batch_size)
for i in range(test_iters):
solver.test_nets[0].forward()
accuracy += solver.test_nets[0].blobs['accuracy'].data
accuracy /= test_iters
print("Accuracy: {:.3f}".format(accuracy))
Accuracy: 0.832
Accuracy: 0.832
Accuracy: 0.832
Accuracy: 0.831
1 loops, best of 3: 386 ms per loop
同样也用命令行看一下模型文件和求解过程:
!./build/tools/caffe train -solver examples/hdf5_classification/nonlinear_solver.prototxt
I0318 00:58:43.336922
caffe.cpp:117] Use CPU.
I0318 00:58:43.654698
caffe.cpp:121] Starting Optimization
I0318 00:58:43.654747
solver.cpp:32] Initializing solver from parameters:
train_net: "examples/hdf5_classification/nonlinear_auto_train.prototxt"
test_net: "examples/hdf5_classification/nonlinear_auto_test.prototxt"
test_iter: 250
test_interval: 1000
base_lr: 0.01
display: 1000
max_iter: 10000
lr_policy: "step"
gamma: 0.1
momentum: 0.9
weight_decay: 0.0005
stepsize: 5000
snapshot: 10000
snapshot_prefix: "examples/hdf5_classification/data/train"
solver_mode: CPU
I0318 00:58:43.654855
solver.cpp:61] Creating training net from train_net file: examples/hdf5_classification/nonlinear_auto_train.prototxt
I0318 00:58:43.655004
net.cpp:42] Initializing net from parameters:
phase: TRAIN
name: "data"
type: "HDF5Data"
top: "data"
top: "label"
hdf5_data_param {
source: "examples/hdf5_classification/data/train.txt"
batch_size: 10
name: "ip1"
type: "InnerProduct"
bottom: "data"
top: "ip1"
inner_product_param {
num_output: 40
weight_filler {
type: "xavier"
name: "relu1"
type: "ReLU"
bottom: "ip1"
top: "ip1"
name: "ip2"
type: "InnerProduct"
bottom: "ip1"
top: "ip2"
inner_product_param {
num_output: 2
weight_filler {
type: "xavier"
name: "accuracy"
type: "Accuracy"
bottom: "ip2"
bottom: "label"
top: "accuracy"
name: "loss"
type: "SoftmaxWithLoss"
bottom: "ip2"
bottom: "label"
top: "loss"
I0318 00:58:43.655120
layer_factory.hpp:74] Creating layer data
I0318 00:58:43.655139
net.cpp:84] Creating Layer data
I0318 00:58:43.655264
net.cpp:338] data -& data
I0318 00:58:43.655297
net.cpp:338] data -& label
I0318 00:58:43.655310
net.cpp:113] Setting up data
I0318 00:58:43.655318
hdf5_data_layer.cpp:66] Loading list of HDF5 filenames from: examples/hdf5_classification/data/train.txt
I0318 00:58:43.655365
hdf5_data_layer.cpp:80] Number of HDF5 files: 2
I0318 00:58:43.657317
net.cpp:120] Top shape: 10 4 (40)
I0318 00:58:43.657342
net.cpp:120] Top shape: 10 (10)
I0318 00:58:43.657356
layer_factory.hpp:74] Creating layer label_data_1_split
I0318 00:58:43.657373
net.cpp:84] Creating Layer label_data_1_split
I0318 00:58:43.657384
net.cpp:380] label_data_1_split &- label
I0318 00:58:43.657395
net.cpp:338] label_data_1_split -& label_data_1_split_0
I0318 00:58:43.657407
net.cpp:338] label_data_1_split -& label_data_1_split_1
I0318 00:58:43.657418
net.cpp:113] Setting up label_data_1_split
I0318 00:58:43.657426
net.cpp:120] Top shape: 10 (10)
I0318 00:58:43.657433
net.cpp:120] Top shape: 10 (10)
I0318 00:58:43.657441
layer_factory.hpp:74] Creating layer ip1
I0318 00:58:43.657451
net.cpp:84] Creating Layer ip1
I0318 00:58:43.657459
net.cpp:380] ip1 &- data
I0318 00:58:43.657467
net.cpp:338] ip1 -& ip1
I0318 00:58:43.657479
net.cpp:113] Setting up ip1
I0318 00:58:43.662454
net.cpp:120] Top shape: 10 40 (400)
I0318 00:58:43.662477
layer_factory.hpp:74] Creating layer relu1
I0318 00:58:43.662497
net.cpp:84] Creating Layer relu1
I0318 00:58:43.662508
net.cpp:380] relu1 &- ip1
I0318 00:58:43.662520
net.cpp:327] relu1 -& ip1 (in-place)
I0318 00:58:43.662530
net.cpp:113] Setting up relu1
I0318 00:58:43.662539
net.cpp:120] Top shape: 10 40 (400)
I0318 00:58:43.662546
layer_factory.hpp:74] Creating layer ip2
I0318 00:58:43.662555
net.cpp:84] Creating Layer ip2
I0318 00:58:43.662562
net.cpp:380] ip2 &- ip1
I0318 00:58:43.662571
net.cpp:338] ip2 -& ip2
I0318 00:58:43.662580
net.cpp:113] Setting up ip2
I0318 00:58:43.662595
net.cpp:120] Top shape: 10 2 (20)
I0318 00:58:43.662606
layer_factory.hpp:74] Creating layer ip2_ip2_0_split
I0318 00:58:43.662654
net.cpp:84] Creating Layer ip2_ip2_0_split
I0318 00:58:43.662665
net.cpp:380] ip2_ip2_0_split &- ip2
I0318 00:58:43.662678
net.cpp:338] ip2_ip2_0_split -& ip2_ip2_0_split_0
I0318 00:58:43.662689
net.cpp:338] ip2_ip2_0_split -& ip2_ip2_0_split_1
I0318 00:58:43.662698
net.cpp:113] Setting up ip2_ip2_0_split
I0318 00:58:43.662706
net.cpp:120] Top shape: 10 2 (20)
I0318 00:58:43.662714
net.cpp:120] Top shape: 10 2 (20)
I0318 00:58:43.662722
layer_factory.hpp:74] Creating layer accuracy
I0318 00:58:43.662734
net.cpp:84] Creating Layer accuracy
I0318 00:58:43.662740
net.cpp:380] accuracy &- ip2_ip2_0_split_0
I0318 00:58:43.662749
net.cpp:380] accuracy &- label_data_1_split_0
I0318 00:58:43.662756
net.cpp:338] accuracy -& accuracy
I0318 00:58:43.662766
net.cpp:113] Setting up accuracy
I0318 00:58:43.662818
net.cpp:120] Top shape: (1)
I0318 00:58:43.662827
layer_factory.hpp:74] Creating layer loss
I0318 00:58:43.662839
net.cpp:84] Creating Layer loss
I0318 00:58:43.662847
net.cpp:380] loss &- ip2_ip2_0_split_1
I0318 00:58:43.662854
net.cpp:380] loss &- label_data_1_split_1
I0318 00:58:43.662863
net.cpp:338] loss -& loss
I0318 00:58:43.662873
net.cpp:113] Setting up loss
I0318 00:58:43.662883
layer_factory.hpp:74] Creating layer loss
I0318 00:58:43.662901
net.cpp:120] Top shape: (1)
I0318 00:58:43.662909
net.cpp:122]
with loss weight 1
I0318 00:58:43.662922
net.cpp:167] loss needs backward computation.
I0318 00:58:43.662930
net.cpp:169] accuracy does not need backward computation.
I0318 00:58:43.662936
net.cpp:167] ip2_ip2_0_split needs backward computation.
I0318 00:58:43.662942
net.cpp:167] ip2 needs backward computation.
I0318 00:58:43.662976
net.cpp:167] relu1 needs backward computation.
I0318 00:58:43.662988
net.cpp:167] ip1 needs backward computation.
I0318 00:58:43.662997
net.cpp:169] label_data_1_split does not need backward computation.
I0318 00:58:43.663003
net.cpp:169] data does not need backward computation.
I0318 00:58:43.663009
net.cpp:205] This network produces output accuracy
I0318 00:58:43.663017
net.cpp:205] This network produces output loss
I0318 00:58:43.663028
net.cpp:447] Collecting Learning Rate and Weight Decay.
I0318 00:58:43.663035
net.cpp:217] Network initialization done.
I0318 00:58:43.663041
net.cpp:218] Memory required for data: 3728
I0318 00:58:43.663158
solver.cpp:154] Creating test net (#0) specified by test_net file: examples/hdf5_classification/nonlinear_auto_test.prototxt
I0318 00:58:43.663179
net.cpp:42] Initializing net from parameters:
phase: TEST
name: "data"
type: "HDF5Data"
top: "data"
top: "label"
hdf5_data_param {
source: "examples/hdf5_classification/data/test.txt"
batch_size: 10
name: "ip1"
type: "InnerProduct"
bottom: "data"
top: "ip1"
inner_product_param {
num_output: 40
weight_filler {
type: "xavier"
name: "relu1"
type: "ReLU"
bottom: "ip1"
top: "ip1"
name: "ip2"
type: "InnerProduct"
bottom: "ip1"
top: "ip2"
inner_product_param {
num_output: 2
weight_filler {
type: "xavier"
name: "accuracy"
type: "Accuracy"
bottom: "ip2"
bottom: "label"
top: "accuracy"
name: "loss"
type: "SoftmaxWithLoss"
bottom: "ip2"
bottom: "label"
top: "loss"
I0318 00:58:43.663349
layer_factory.hpp:74] Creating layer data
I0318 00:58:43.663365
net.cpp:84] Creating Layer data
I0318 00:58:43.663373
net.cpp:338] data -& data
I0318 00:58:43.663385
net.cpp:338] data -& label
I0318 00:58:43.663396
net.cpp:113] Setting up data
I0318 00:58:43.663422
hdf5_data_layer.cpp:66] Loading list of HDF5 filenames from: examples/hdf5_classification/data/test.txt
I0318 00:58:43.663457
hdf5_data_layer.cpp:80] Number of HDF5 files: 1
I0318 00:58:43.664719
net.cpp:120] Top shape: 10 4 (40)
I0318 00:58:43.664739
net.cpp:120] Top shape: 10 (10)
I0318 00:58:43.664754
layer_factory.hpp:74] Creating layer label_data_1_split
I0318 00:58:43.664772
net.cpp:84] Creating Layer label_data_1_split
I0318 00:58:43.664783
net.cpp:380] label_data_1_split &- label
I0318 00:58:43.664791
net.cpp:338] label_data_1_split -& label_data_1_split_0
I0318 00:58:43.664803
net.cpp:338] label_data_1_split -& label_data_1_split_1
I0318 00:58:43.664813
net.cpp:113] Setting up label_data_1_split
I0318 00:58:43.664822
net.cpp:120] Top shape: 10 (10)
I0318 00:58:43.664829
net.cpp:120] Top shape: 10 (10)
I0318 00:58:43.664837
layer_factory.hpp:74] Creating layer ip1
I0318 00:58:43.664846
net.cpp:84] Creating Layer ip1
I0318 00:58:43.664854
net.cpp:380] ip1 &- data
I0318 00:58:43.664862
net.cpp:338] ip1 -& ip1
I0318 00:58:43.664875
net.cpp:113] Setting up ip1
I0318 00:58:43.664901
net.cpp:120] Top shape: 10 40 (400)
I0318 00:58:43.664924
layer_factory.hpp:74] Creating layer relu1
I0318 00:58:43.664945
net.cpp:84] Creating Layer relu1
I0318 00:58:43.664958
net.cpp:380] relu1 &- ip1
I0318 00:58:43.664966
net.cpp:327] relu1 -& ip1 (in-place)
I0318 00:58:43.664975
net.cpp:113] Setting up relu1
I0318 00:58:43.664983
net.cpp:120] Top shape: 10 40 (400)
I0318 00:58:43.664990
layer_factory.hpp:74] Creating layer ip2
I0318 00:58:43.665000
net.cpp:84] Creating Layer ip2
I0318 00:58:43.665006
net.cpp:380] ip2 &- ip1
I0318 00:58:43.665015
net.cpp:338] ip2 -& ip2
I0318 00:58:43.665030
net.cpp:113] Setting up ip2
I0318 00:58:43.665052
net.cpp:120] Top shape: 10 2 (20)
I0318 00:58:43.665066
layer_factory.hpp:74] Creating layer ip2_ip2_0_split
I0318 00:58:43.665077
net.cpp:84] Creating Layer ip2_ip2_0_split
I0318 00:58:43.665086
net.cpp:380] ip2_ip2_0_split &- ip2
I0318 00:58:43.665093
net.cpp:338] ip2_ip2_0_split -& ip2_ip2_0_split_0
I0318 00:58:43.665103
net.cpp:338] ip2_ip2_0_split -& ip2_ip2_0_split_1
I0318 00:58:43.665113
net.cpp:113] Setting up ip2_ip2_0_split
I0318 00:58:43.665122
net.cpp:120] Top shape: 10 2 (20)
I0318 00:58:43.665128
net.cpp:120] Top shape: 10 2 (20)
I0318 00:58:43.665137
layer_factory.hpp:74] Creating layer accuracy
I0318 00:58:43.665144
net.cpp:84] Creating Layer accuracy
I0318 00:58:43.665153
net.cpp:380] accuracy &- ip2_ip2_0_split_0
I0318 00:58:43.665168
net.cpp:380] accuracy &- label_data_1_split_0
I0318 00:58:43.665180
net.cpp:338] accuracy -& accuracy
I0318 00:58:43.665192
net.cpp:113] Setting up accuracy
I0318 00:58:43.665200
net.cpp:120] Top shape: (1)
I0318 00:58:43.665207
layer_factory.hpp:74] Creating layer loss
I0318 00:58:43.665216
net.cpp:84] Creating Layer loss
I0318 00:58:43.665223
net.cpp:380] loss &- ip2_ip2_0_split_1
I0318 00:58:43.665230
net.cpp:380] loss &- label_data_1_split_1
I0318 00:58:43.665241
net.cpp:338] loss -& loss
I0318 00:58:43.665251
net.cpp:113] Setting up loss
I0318 00:58:43.665259
layer_factory.hpp:74] Creating layer loss
I0318 00:58:43.665273
net.cpp:120] Top shape: (1)
I0318 00:58:43.665282
net.cpp:122]
with loss weight 1
I0318 00:58:43.665290
net.cpp:167] loss needs backward computation.
I0318 00:58:43.665338
net.cpp:169] accuracy does not need backward computation.
I0318 00:58:43.665351
net.cpp:167] ip2_ip2_0_split needs backward computation.
I0318 00:58:43.665380
net.cpp:167] ip2 needs backward computation.
I0318 00:58:43.665387
net.cpp:167] relu1 needs backward computation.
I0318 00:58:43.665393
net.cpp:167] ip1 needs backward computation.
I0318 00:58:43.665400
net.cpp:169] label_data_1_split does not need backward computation.
I0318 00:58:43.665407
net.cpp:169] data does not need backward computation.
I0318 00:58:43.665415
net.cpp:205] This network produces output accuracy
I0318 00:58:43.665421
net.cpp:205] This network produces output loss
I0318 00:58:43.665431
net.cpp:447] Collecting Learning Rate and Weight Decay.
I0318 00:58:43.665441
net.cpp:217] Network initialization done.
I0318 00:58:43.665446
net.cpp:218] Memory required for data: 3728
I0318 00:58:43.665534
solver.cpp:42] Solver scaffolding done.
I0318 00:58:43.665568
solver.cpp:222] Solving
I0318 00:58:43.665577
solver.cpp:223] Learning Rate Policy: step
I0318 00:58:43.665586
solver.cpp:266] Iteration 0, Testing net (#0)
I0318 00:58:43.683938
solver.cpp:315]
Test net output #0: accuracy = 0.5184
I0318 00:58:43.683981
solver.cpp:315]
Test net output #1: loss = 0.716141 (* 1 = 0.716141 loss)
I0318 00:58:43.684236
solver.cpp:189] Iteration 0, loss = 0.764954
I0318 00:58:43.684267
solver.cpp:204]
Train net output #0: accuracy = 0.5
I0318 00:58:43.684285
solver.cpp:204]
Train net output #1: loss = 0.764954 (* 1 = 0.764954 loss)
I0318 00:58:43.684305
solver.cpp:464] Iteration 0, lr = 0.01
I0318 00:58:43.714700
solver.cpp:266] Iteration 1000, Testing net (#0)
I0318 00:58:43.721762
solver.cpp:315]
Test net output #0: accuracy = 0.8168
I0318 00:58:43.721818
solver.cpp:315]
Test net output #1: loss = 0.434918 (* 1 = 0.434918 loss)
I0318 00:58:43.721899
solver.cpp:189] Iteration 1000, loss = 0.282425
I0318 00:58:43.721917
solver.cpp:204]
Train net output #0: accuracy = 0.9
I0318 00:58:43.721932
solver.cpp:204]
Train net output #1: loss = 0.282426 (* 1 = 0.282426 loss)
I0318 00:58:43.721942
solver.cpp:464] Iteration 1000, lr = 0.01
I0318 00:58:43.750509
solver.cpp:266] Iteration 2000, Testing net (#0)
I0318 00:58:43.754590
solver.cpp:315]
Test net output #0: accuracy = 0.8224
I0318 00:58:43.754621
solver.cpp:315]
Test net output #1: loss = 0.416874 (* 1 = 0.416874 loss)
I0318 00:58:43.754660
solver.cpp:189] Iteration 2000, loss = 0.51988
I0318 00:58:43.754672
solver.cpp:204]
Train net output #0: accuracy = 0.7
I0318 00:58:43.754683
solver.cpp:204]
Train net output #1: loss = 0.51988 (* 1 = 0.51988 loss)
I0318 00:58:43.754690
solver.cpp:464] Iteration 2000, lr = 0.01
I0318 00:58:43.782609
solver.cpp:266] Iteration 3000, Testing net (#0)
I0318 00:58:43.789728
solver.cpp:315]
Test net output #0: accuracy = 0.8176
I0318 00:58:43.789777
solver.cpp:315]
Test net output #1: loss = 0.415907 (* 1 = 0.415907 loss)
I0318 00:58:43.790487
solver.cpp:189] Iteration 3000, loss = 0.5093
I0318 00:58:43.790510
solver.cpp:204]
Train net output #0: accuracy = 0.7
I0318 00:58:43.790530
solver.cpp:204]
Train net output #1: loss = 0.509301 (* 1 = 0.509301 loss)
I0318 00:58:43.790544
solver.cpp:464] Iteration 3000, lr = 0.01
I0318 00:58:43.817451
solver.cpp:266] Iteration 4000, Testing net (#0)
I0318 00:58:43.821740
solver.cpp:315]
Test net output #0: accuracy = 0.8252
I0318 00:58:43.821770
solver.cpp:315]
Test net output #1: loss = 0.409124 (* 1 = 0.409124 loss)
I0318 00:58:43.821822
solver.cpp:189] Iteration 4000, loss = 0.284815
I0318 00:58:43.821835
solver.cpp:204]
Train net output #0: accuracy = 0.9
I0318 00:58:43.821846
solver.cpp:204]
Train net output #1: loss = 0.284815 (* 1 = 0.284815 loss)
I0318 00:58:43.821890
solver.cpp:464] Iteration 4000, lr = 0.01
I0318 00:58:43.847015
solver.cpp:266] Iteration 5000, Testing net (#0)
I0318 00:58:43.852102
solver.cpp:315]
Test net output #0: accuracy = 0.8256
I0318 00:58:43.852145
solver.cpp:315]
Test net output #1: loss = 0.404445 (* 1 = 0.404445 loss)
I0318 00:58:43.852188
solver.cpp:189] Iteration 5000, loss = 0.511566
I0318 00:58:43.852200
solver.cpp:204]
Train net output #0: accuracy = 0.7
I0318 00:58:43.852210
solver.cpp:204]
Train net output #1: loss = 0.511566 (* 1 = 0.511566 loss)
I0318 00:58:43.852219
solver.cpp:464] Iteration 5000, lr = 0.001
I0318 00:58:43.876060
solver.cpp:266] Iteration 6000, Testing net (#0)
I0318 00:58:43.880080
solver.cpp:315]
Test net output #0: accuracy = 0.8328
I0318 00:58:43.880105
solver.cpp:315]
Test net output #1: loss = 0.396847 (* 1 = 0.396847 loss)
I0318 00:58:43.880700
solver.cpp:189] Iteration 6000, loss = 0.397858
I0318 00:58:43.880718
solver.cpp:204]
Train net output #0: accuracy = 0.9
I0318 00:58:43.880729
solver.cpp:204]
Train net output #1: loss = 0.397858 (* 1 = 0.397858 loss)
I0318 00:58:43.880738
solver.cpp:464] Iteration 6000, lr = 0.001
I0318 00:58:43.913795
solver.cpp:266] Iteration 7000, Testing net (#0)
I0318 00:58:43.917851
solver.cpp:315]
Test net output #0: accuracy = 0.8316
I0318 00:58:43.917876
solver.cpp:315]
Test net output #1: loss = 0.398135 (* 1 = 0.398135 loss)
I0318 00:58:43.917956
solver.cpp:189] Iteration 7000, loss = 0.243849
I0318 00:58:43.917971
solver.cpp:204]
Train net output #0: accuracy = 0.9
I0318 00:58:43.917989
solver.cpp:204]
Train net output #1: loss = 0.243849 (* 1 = 0.243849 loss)
I0318 00:58:43.918002
solver.cpp:464] Iteration 7000, lr = 0.001
I0318 00:58:43.943681
solver.cpp:266] Iteration 8000, Testing net (#0)
I0318 00:58:43.947589
solver.cpp:315]
Test net output #0: accuracy = 0.8312
I0318 00:58:43.947615
solver.cpp:315]
Test net output #1: loss = 0.394763 (* 1 = 0.394763 loss)
I0318 00:58:43.947651
solver.cpp:189] Iteration 8000, loss = 0.513399
I0318 00:58:43.947664
solver.cpp:204]
Train net output #0: accuracy = 0.7
I0318 00:58:43.947674
solver.cpp:204]
Train net output #1: loss = 0.513399 (* 1 = 0.513399 loss)
I0318 00:58:43.947682
solver.cpp:464] Iteration 8000, lr = 0.001
I0318 00:58:43.973080
solver.cpp:266] Iteration 9000, Testing net (#0)
I0318 00:58:43.977033
solver.cpp:315]
Test net output #0: accuracy = 0.834
I0318 00:58:43.977056
solver.cpp:315]
Test net output #1: loss = 0.395663 (* 1 = 0.395663 loss)
I0318 00:58:43.977710
solver.cpp:189] Iteration 9000, loss = 0.399341
I0318 00:58:43.977735
solver.cpp:204]
Train net output #0: accuracy = 0.9
I0318 00:58:43.977746
solver.cpp:204]
Train net output #1: loss = 0.399342 (* 1 = 0.399342 loss)
I0318 00:58:43.977756
solver.cpp:464] Iteration 9000, lr = 0.001
I0318 00:58:44.003437
solver.cpp:334] Snapshotting to examples/hdf5_classification/data/train_iter_10000.caffemodel
I0318 00:58:44.003702
solver.cpp:342] Snapshotting solver state to examples/hdf5_classification/data/train_iter_10000.solverstate
I0318 00:58:44.003850
solver.cpp:248] Iteration 10000, loss = 0.244639
I0318 00:58:44.003871
solver.cpp:266] Iteration 10000, Testing net (#0)
I0318 00:58:44.008216
solver.cpp:315]
Test net output #0: accuracy = 0.8308
I0318 00:58:44.008252
solver.cpp:315]
Test net output #1: loss = 0.397291 (* 1 = 0.397291 loss)
I0318 00:58:44.008262
solver.cpp:253] Optimization Done.
I0318 00:58:44.008270
caffe.cpp:134] Optimization Done.
最后把这些数据删掉:
# Clean up (comment this out if you want to examine the hdf5_classification/data directory).
shutil.rmtree(dirname)
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:142348次
积分:1973
积分:1973
排名:第17934名
原创:36篇
评论:182条
(1)(7)(1)(1)(2)(1)(10)(2)(5)(7)(5)(1)}

我要回帖

更多关于 caffe做回归 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信