caffe Python API 之Accuracy】的更多相关文章

net.acc = caffe.layers.Accuracy(net.fc3,net.label) 输出: layer { name: "acc" type: "Accuracy" bottom: "fc3" bottom: "label" top: "acc" }…
一.显示各层 # params显示:layer名,w,b for layer_name, param in net.params.items(): print layer_name + '\t' + str(param[0].data.shape), str(param[1].data.shape) # blob显示:layer名,输出的blob维度 for layer_name, blob in net.blobs.items(): print layer_name + '\t' + str(…
# 编写一个函数,将二进制的均值转换为python的均值 def convert_mean(binMean,npyMean): blob = caffe.proto.caffe_pb2.BlobProto() bin_mean = open(binMean, 'rb' ).read() blob.ParseFromString(bin_mean) arr = np.array( caffe.io.blobproto_to_array(blob) ) npy_mean = arr[0] np.sa…
import sys import os sys.path.append("/projects/caffe-ssd/python") import caffe net = caffe.NetSpec() net.data, net.label = caffe.layers.Data( name="InputData", source="train_lmdb", backend = caffe.params.Data.LMDB, batch_siz…
import sys sys.path.append('/projects/caffe-ssd/python') import caffe4 net = caffe.NetSpec() 一.ImageData Layer net.data ,net.label = caffe.layers.ImageData( name="InputData" source="train.txt", batch_size=32, new_width=48, new_height=4…
net.bn = caffe.layers.BatchNorm( net.conv1, batch_norm_param=dict( moving_average_fraction=0.90, #滑动平均的衰减系数,默认为0.999 use_global_stats=False, #如果为真,则使用保存的均值和方差,否则采用滑动平均计算新的均值和方差. # 该参数缺省的时候,如果是测试阶段则等价为真,如果是训练阶段则等价为假. eps=1e-5 #分母附加值,防止除以方差时出现除0操作,默认为1…
对于convolution: output = (input + 2 * p  - k)  / s + 1; 对于deconvolution: output = (input - 1) * s + k - 2 * p; net.deconv = caffe.layers.Deconvolution( net.conv1, param={"lr_mult": 1, "decay_mult": 1}, convolution_param=dict( num_output…
#以SSD的检测测试为例 def detetion(image_dir,weight,deploy,resolution=300): caffe.set_mode_gpu() net = caffe.Net(weight,deploy,caffe.TEST) transformer = caffe.io.Transformer({'data': net.blobs['data'].data.shape}) transformer.set_transpose('data',(2,0,1)) tra…
# 设定图片的shape格式为网络data层格式 transformer = caffe.io.Transformer({'data': net.blobs['data'].data.shape}) # 改变维度的顺序,由原始图片维度(width, height, channel)变为(channel, width, height) transformer.set_transpose('data', (2,0,1)) # 减去均值,注意要先将binaryproto格式均值文件转换为npy格式[此…
# 训练设置 # 使用GPU caffe.set_device(gpu_id) # 若不设置,默认为0 caffe.set_mode_gpu() # 使用CPU caffe.set_mode_cpu() # 加载Solver,有两种常用方法 # 1. 无论模型中Slover类型是什么统一设置为SGD solver = caffe.SGDSolver('/home/xxx/data/solver.prototxt') # 2. 根据solver的prototxt中solver_type读取,默认为…