caffe (10) 使用python测试多张图片统计分类结果
来源:互联网 发布:黑魂3男捏脸数据 编辑:程序博客网 时间:2024/05/18 20:32
直接上代码啦, test.py
#coding=utf-8 import osimport numpy as npimport caffe import matplotlib.pyplot as plt root='/home/xxx/caffe/'deploy=root + 'examples/myfile2/cifar10_quick.prototxt' print("deploy = %s\n" %deploy) caffe_model=root + 'examples/myfile2/cifar10_quick_iter_300.caffemodel' print("caffe_model = %s\n" %caffe_model) mean_file = root + 'examples/myfile2/mean.npy'print("mean_file = %s\n" %mean_file) labels_filename = root+'examples/myfile2/test/label.txt'print("labels_filename = %s\n" %labels_filename) #######################################################3net = caffe.Net(deploy,caffe_model,caffe.TEST) caffe.set_mode_cpu()transformer = caffe.io.Transformer({'data': net.blobs['data'].data.shape}) transformer.set_transpose('data', (2,0,1)) transformer.set_mean('data', np.load(mean_file).mean(1).mean(1)) transformer.set_raw_scale('data', 255)#transformer.set_channel_swap(‘data‘, (2,1,0)) ########################################################path=root + 'examples/myfile2/test/images.txt'print("path = %s\n" %path) fp = open(labels_filename)fout = open(root+'examples/myfile2/test/badClassification.txt', 'w')num = 0 for line in open(path): #print line line=line.strip('\n') fullfilename = root+'examples/myfile2/test/'+line #print("fullfilename = %s" %fullfilename) #fullfilename.replace("\n","") im=caffe.io.load_image(fullfilename, False) net.blobs['data'].data[...] = transformer.preprocess('data',im) #执行测试 out = net.forward() labels = np.loadtxt(labels_filename, str, delimiter='\t') prob= net.blobs['prob'].data[0].flatten() order=prob.argsort()[2] line2 = fp.readline() line2.replace("\n", "") line2.replace("\t", "") #print("label = %s predict = %s\n" %(line2, order)) if int(line2) != int(order): num = num+1 print fullfilename fout.write(fullfilename) fout.write('\n')print num
cifar10_quick.prototxt is as follows:
name: "CIFAR10_quick_test"layer { name: "data" type: "Input" top: "data" input_param { shape: { dim: 1 dim: 1 dim: 64 dim: 64 } }}layer { name: "conv1" type: "Convolution" bottom: "data" top: "conv1" param { lr_mult: 1 } param { lr_mult: 2 } convolution_param { num_output: 32 pad: 2 kernel_size: 5 stride: 1 }}layer { name: "pool1" type: "Pooling" bottom: "conv1" top: "pool1" pooling_param { pool: MAX kernel_size: 3 stride: 2 }}layer { name: "relu1" type: "ReLU" bottom: "pool1" top: "pool1"}layer { name: "conv2" type: "Convolution" bottom: "pool1" top: "conv2" param { lr_mult: 1 } param { lr_mult: 2 } convolution_param { num_output: 32 pad: 2 kernel_size: 5 stride: 1 }}layer { name: "relu2" type: "ReLU" bottom: "conv2" top: "conv2"}layer { name: "pool2" type: "Pooling" bottom: "conv2" top: "pool2" pooling_param { pool: AVE kernel_size: 3 stride: 2 }}layer { name: "conv3" type: "Convolution" bottom: "pool2" top: "conv3" param { lr_mult: 1 } param { lr_mult: 2 } convolution_param { num_output: 64 pad: 2 kernel_size: 5 stride: 1 }}layer { name: "relu3" type: "ReLU" bottom: "conv3" top: "conv3"}layer { name: "pool3" type: "Pooling" bottom: "conv3" top: "pool3" pooling_param { pool: AVE kernel_size: 3 stride: 2 }}layer { name: "ip1" type: "InnerProduct" bottom: "pool3" top: "ip1" param { lr_mult: 1 } param { lr_mult: 2 } inner_product_param { num_output: 64 }}layer { name: "ip2" type: "InnerProduct" bottom: "ip1" top: "ip2" param { lr_mult: 1 } param { lr_mult: 2 } inner_product_param { num_output: 3 }}layer { name: "prob" type: "Softmax" bottom: "ip2" top: "prob"}
cifar10_quick_train_test.prototxt is as follows:
name: "CIFAR10_quick"layer { name: "cifar" type: "Data" top: "data" top: "label" include { phase: TRAIN } transform_param { mean_file: "examples/myfile2/mean.binaryproto" } data_param { source: "examples/myfile2/img_train_lmdb" batch_size: 50 backend: LMDB }}layer { name: "cifar" type: "Data" top: "data" top: "label" include { phase: TEST } transform_param { mean_file: "examples/myfile2/mean.binaryproto" } data_param { source: "examples/myfile2/img_test_lmdb" batch_size: 50 backend: LMDB }}layer { name: "conv1" type: "Convolution" bottom: "data" top: "conv1" param { lr_mult: 1 } param { lr_mult: 2 } convolution_param { num_output: 32 pad: 2 kernel_size: 5 stride: 1 weight_filler { type: "gaussian" std: 0.0001 } bias_filler { type: "constant" } }}layer { name: "pool1" type: "Pooling" bottom: "conv1" top: "pool1" pooling_param { pool: MAX kernel_size: 3 stride: 2 }}layer { name: "relu1" type: "ReLU" bottom: "pool1" top: "pool1"}layer { name: "conv2" type: "Convolution" bottom: "pool1" top: "conv2" param { lr_mult: 1 } param { lr_mult: 2 } convolution_param { num_output: 32 pad: 2 kernel_size: 5 stride: 1 weight_filler { type: "gaussian" std: 0.01 } bias_filler { type: "constant" } }}layer { name: "relu2" type: "ReLU" bottom: "conv2" top: "conv2"}layer { name: "pool2" type: "Pooling" bottom: "conv2" top: "pool2" pooling_param { pool: AVE kernel_size: 3 stride: 2 }}layer { name: "conv3" type: "Convolution" bottom: "pool2" top: "conv3" param { lr_mult: 1 } param { lr_mult: 2 } convolution_param { num_output: 64 pad: 2 kernel_size: 5 stride: 1 weight_filler { type: "gaussian" std: 0.01 } bias_filler { type: "constant" } }}layer { name: "relu3" type: "ReLU" bottom: "conv3" top: "conv3"}layer { name: "pool3" type: "Pooling" bottom: "conv3" top: "pool3" pooling_param { pool: AVE kernel_size: 3 stride: 2 }}layer { name: "ip1" type: "InnerProduct" bottom: "pool3" top: "ip1" param { lr_mult: 1 } param { lr_mult: 2 } inner_product_param { num_output: 64 weight_filler { type: "gaussian" std: 0.1 } bias_filler { type: "constant" } }}layer { name: "ip2" type: "InnerProduct" bottom: "ip1" top: "ip2" param { lr_mult: 1 } param { lr_mult: 2 } inner_product_param { num_output: 3 weight_filler { type: "gaussian" std: 0.1 } bias_filler { type: "constant" } }}layer { name: "accuracy" type: "Accuracy" bottom: "ip2" bottom: "label" top: "accuracy" include { phase: TEST }}layer { name: "loss" type: "SoftmaxWithLoss" bottom: "ip2" bottom: "label" top: "loss"}
阅读全文
0 0
- caffe (10) 使用python测试多张图片统计分类结果
- 使用caffe的python接口预测多张图片
- caffe python接口 测试分类:
- 用caffe自带的训练好的模型测试图片的分类结果,实现啦啦啦
- 使用Caffe进行图片分类
- caffe训练模型后,使用模型测试的分类结果全部都是相同的
- caffe-python接口图片分类demo
- Caffe : Python中使用已有模型测试图像分类情况
- Python拼接多张图片
- caffe+python 使用训练好的VGG16模型 对 单张图片进行分类,输出置信度
- caffe+python 使用训练好的VGG16模型 对 单张图片进行分类,输出置信度
- 【用Python学习Caffe】1. 使用Caffe完成图像分类
- Caffe图片分类
- caffe+python+mnist从图片训练到测试单张图片
- caffe+python+mnist从图片训练到测试单张图片
- caffe 使用python测试ImageNet classification
- iOS上传语音、文字、图片(分类 多张)
- 使用python调用训练好的caffe模型来分类
- 网狐6.6完整商业版源码架设最新棋牌游戏源码下载
- 推荐系统
- js模拟手机短信对话
- java 用单链表实现队列
- Maven
- caffe (10) 使用python测试多张图片统计分类结果
- java中的简单碰撞检测
- 最大流-dinic算法
- RxJava、RxAndroid中的几个线程控制器
- 对于上限为int,java.lang.Object 的类型变量 T
- 【Java】List和String [] 的相互转换
- DBExportDoc-For-MySQL连接数据库报错的解决
- Springboot 配置详解
- 注解内容提取(类上、方法上)