当前位置:网站首页>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
边栏推荐
- 终端安全能力验证环境搭建和渗透测试记录
- Web Service简单入门示例
- Modifiers of attributes of TS public, private, protect
- 启牛2980有没有用?开户安全吗、
- 基於flask寫一個接口
- JS common method encapsulation
- XML建模
- ArcGIS\QGIS无插件加载(无偏移)MapBox高清影像图
- Comparison table of foreign lead American abbreviations
- Access Zadig self-test environment outside the cluster based on ingress controller (best practice)
猜你喜欢

请查收.NET MAUI 的最新学习资源

The transformation based on vertx web sstore redis to realize the distributed session of vertx HTTP application
![R language [data management]](/img/41/b89bb8794c06280e58988e1c1a5e02.png)
R language [data management]

第05章_存储引擎

ArcGIS栅格重采样方法介绍

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

秋招将临 如何准备算法面试、回答算法面试题

Research and development efficiency improvement practice of large insurance groups with 10000 + code base and 3000 + R & D personnel
![最长摆动序列[贪心练习]](/img/e1/70dc21b924232c7e5e3da023a4bed2.png)
最长摆动序列[贪心练习]

面试官:并发编程实战会吗?(线程控制操作详解)
随机推荐
Why can't Chinese software companies produce products? Abandon the Internet after 00; Open source high-performance API gateway component of station B | weekly email exclusive to VIP members of Menon w
ODPS 下一个map / reduce 准备
Clion configures Visual Studio (MSVC) and JOM multi-core compilation
《SAS编程和数据挖掘商业案例》学习笔记# 19
EN 438-7 laminated sheet products for building covering decoration - CE certification
LeetCode_哈希表_困难_149. 直线上最多的点数
How to send samples when applying for BS 476-7 display? Is it the same as the display??
LeetCode: Distinct Subsequences [115]
ClickHouse 复制粘贴多行sql语句报错
Selenium finds the contents of B or P Tags
Is Kai Niu 2980 useful? Is it safe to open an account
LeetCode_ Hash table_ Difficulties_ 149. Maximum number of points on the line
Dictionary tree simple introductory question (actually blue question?)
Mathematical analysis_ Notes_ Chapter 9: curve integral and surface integral
字典树简单入门题(居然是蓝题?)
POJ 3414 pots (bfs+ clues)
Prior knowledge of machine learning in probability theory (Part 1)
Deep merge object deep copy of vant source code parsing
Simple getting started example of Web Service
Introduction of ArcGIS grid resampling method