当前位置:网站首页>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 catNote 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/103617431I 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
边栏推荐
- Prior knowledge of machine learning in probability theory (Part 1)
- Clion configures Visual Studio (MSVC) and JOM multi-core compilation
- Selenium finds the contents of B or P Tags
- 大二下个人发展小结
- 股票开户选择哪家证券公司比较好哪家平台更安全
- ODPs next map / reduce preparation
- Matplotlib drawing retouching (how to form high-quality drawings, such as how to set fonts, etc.)
- JS common method encapsulation
- EasyExcel的讀寫操作
- 学习机器人无从下手?带你体会当下机器人热门研究方向有哪些
猜你喜欢

Golang (1) | from environmental preparation to quick start

Mathematical analysis_ Notes_ Chapter 9: curve integral and surface integral

Golang(1)|从环境准备到快速上手

示波器探头对信号源阻抗的影响

EasyExcel的讀寫操作

Clickhouse copy paste multi line SQL statement error

【案例】元素的显示与隐藏的运用--元素遮罩

浅聊我和一些编程语言的缘分

中国的软件公司为什么做不出产品?00后抛弃互联网;B站开源的高性能API网关组件|码农周刊VIP会员专属邮件周报 Vol.097

leetcode:1139. 最大的以 1 为边界的正方形
随机推荐
Mathematical analysis_ Notes_ Chapter 9: curve integral and surface integral
wpf 获取datagrid 中指定行列的DataGridTemplateColumn中的控件
【案例】元素的显示与隐藏的运用--元素遮罩
Research and development efficiency improvement practice of large insurance groups with 10000 + code base and 3000 + R & D personnel
Access Zadig self-test environment outside the cluster based on ingress controller (best practice)
Écrire une interface basée sur flask
Selenium finds the contents of B or P Tags
Web Service简单入门示例
ts 之 泛型
XML modeling
The reason why the ncnn converted model on raspberry pie 4B always crashes when called
字典树简单入门题(居然是蓝题?)
Establishment of terminal security capability verification environment and penetration test records
Longest swing sequence [greedy practice]
ts 之 类的简介、构造函数和它的this、继承、抽象类、接口
Pytoch practice -- MNIST dataset handwritten digit recognition
Learning notes of SAS programming and data mining business case 19
PVC 塑料片BS 476-6 火焰传播性能测定
Clickhouse copy paste multi line SQL statement error
Promouvoir le développement de l'industrie culturelle et touristique par la recherche, l'apprentissage et l'enseignement pratique du tourisme