当前位置:网站首页>Teach yourself to train pytorch model to Caffe (III)
Teach yourself to train pytorch model to Caffe (III)
2022-07-05 21:09:00 【FeboReigns】
This section uses caffe To reason out pytorh The same result
Reference resources : Use Caffe Of Python Interface for reasoning - Simple books (jianshu.com)
#coding = utf-8
import numpy as np
import sys, os
sys.path.insert(0, caffe_root + 'python')
import caffe
os.chdir(caffe_root)
#caffe.set_device(0)
#caffe.set_mode_gpu()
#### The following three lines are modified according to their own path
net_file = './dock_googlenet_dog.prototxt'
caffe_model = './dock_googlenet_dog.caffemodel'
imagenet_labels_filename = './class_names.txt'
# load model
net = caffe.Net(net_file, caffe_model, caffe.TEST)
#resize
transformer = caffe.io.Transformer({'data': net.blobs['data'].data.shape})
# Get the number of channels to the front Turn into 【1,3 224,224】
transformer.set_transpose('data', (2, 0, 1))
# # Call the mean file
# # transformer.set_mean('data', np.load(mean_file).mean(1).mean(1))
#python Store pictures as [0, 1], and caffe Store pictures as [0, 255], So we need a transformation
# transformer.set_raw_scale('data', 255)
#caffe The picture is RGB Format , And network format BGR, To transform
# transformer.set_channel_swap('data', (2, 1, 0))
### Change according to your own path
im = caffe.io.load_image('./cat.2.jpg')
net.blobs['data'].data[...] = transformer.preprocess('data',im)
# net.blobs['data'].data[...] =
out = net.forward()
print (net.blobs['data'].data.shape)
print (net.blobs['data'].data.dtype)
print (net.blobs[net.blobs.keys()[-1]].data.shape)
print (net.blobs[net.blobs.keys()[-1]].data.dtype)
labels = np.loadtxt(imagenet_labels_filename, str, delimiter='\t')
top_k = net.blobs[net.blobs.keys()[-1]].data[0].flatten().argsort()[-1:-6:-1]
for i in np.arange(top_k.size):
print (top_k[i], labels[top_k[i]])
# Print the final score
print (net.blobs[net.blobs.keys()[-1]].data[0])
./class_names.txt Namely
0 dog
1 cat
Note that my training is not used normlize,
And my format is RGB Of , So I have a few useless preprocessing
caffe Of caffe.io.load_image('./cat.2.jpg') yes RGB Of
Mine is also. RBG Of
If you use brother's docker My code will report three errors when the environment runs
###got an unexpected keyword argument ‘as_grey‘
https://blog.csdn.net/hjxu2016/article/details/113541609
###TypeError: 'float' object cannot be interpreted as an integer
https://blog.csdn.net/qq_28634403/article/details/81224291
###dict_keys‘ object is not subscriptable
https://blog.csdn.net/le___le/article/details/103617431
I use my own configuration caffe, my caffe No, ceil mode Parameters , use round_mode Instead of the , If ceil mode by true be round_mode by 0, Otherwise, vice versa . Accuracy basically does not affect Pytorch maxpool Of ceil_mode And caffe in maxpool Comparison _zl3090 The blog of -CSDN Blog
How to match yourself caffe Look at my other blog :
finally ubuntu Finished compiling CPU edition caffe 了 _FeboReigns The blog of -CSDN Blog
边栏推荐
- 2022-07-03-CKA-粉丝反馈最新情况
- @Validated basic parameter verification, grouping parameter verification and nested parameter verification
- Determine the best implementation of horizontal and vertical screens
- PHP deserialization +md5 collision
- Test of incombustibility of cement adhesives BS 476-4
- Utils/index TS tool function
- php中explode函数存在的陷阱
- 当用户登录,经常会有实时的下拉框,例如,输入邮箱,将会@qq.com,@163.com,@sohu.com
- EN 438-7建筑覆盖物装饰用层压板材产品—CE认证
- postgres 建立连接并删除记录
猜你喜欢
显示器要申请BS 476-7 怎么送样?跟显示屏一样吗??
EasyExcel的讀寫操作
秋招将临 如何准备算法面试、回答算法面试题
haas506 2.0开发教程 - 阿里云ota - pac 固件升级(仅支持2.2以上版本)
R语言【数据管理】
leetcode:1139. The largest square bounded by 1
PVC 塑料片BS 476-6 火焰传播性能测定
实现浏览页面时校验用户是否已经完成登录的功能
Longest swing sequence [greedy practice]
EN 438-7 laminated sheet products for building covering decoration - CE certification
随机推荐
ts 之 属性的修饰符public、private、protect
systemd-resolved 开启 debug 日志
ViewRootImpl和WindowManagerService笔记
When a user logs in, there is often a real-time drop-down box. For example, entering an email will @qq com,@163. com,@sohu. com
SQL series (basic) - Chapter 2 limiting and sorting data
Establishment of terminal security capability verification environment and penetration test records
字典树简单入门题(居然是蓝题?)
selenium 查找b或p标签的内容
What are the requirements of UL 2043 test for drive housing in the United States?
shell编程100例
PVC 塑料片BS 476-6 火焰传播性能测定
poj 3414 Pots (bfs+线索)
LeetCode_哈希表_困难_149. 直线上最多的点数
ODPS 下一个map / reduce 准备
XML建模
[case] Application of positioning - Taobao rotation map
【日常训练--腾讯精选50】89. 格雷编码(看题解才会的)
终端安全能力验证环境搭建和渗透测试记录
显示器要申请BS 476-7 怎么送样?跟显示屏一样吗??
Research and development efficiency improvement practice of large insurance groups with 10000 + code base and 3000 + R & D personnel