当前位置:网站首页>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
边栏推荐
- AITM 2-0003 水平燃烧试验
- Add ICO icon to clion MinGW compiled EXE file
- ViewRootImpl和WindowManagerService笔记
- PVC 塑料片BS 476-6 火焰传播性能测定
- 显示器要申请BS 476-7 怎么送样?跟显示屏一样吗??
- ClickHouse 复制粘贴多行sql语句报错
- 水泥胶黏剂BS 476-4 不燃性测试
- Which is the best online collaboration product? Microsoft loop, notion, flowus
- Clion-MinGW编译后的exe文件添加ico图标
- Clickhouse copy paste multi line SQL statement error
猜你喜欢

珍爱网微服务底层框架演进从开源组件封装到自研

研學旅遊實踐教育的開展助力文旅產業發展

Display DIN 4102-1 Class B1 fire test requirements
![[case] Application of positioning - Taobao rotation map](/img/2d/c834ce95a2c8e53a20e67fa2e99439.png)
[case] Application of positioning - Taobao rotation map

Using webassembly to operate excel on the browser side

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

The development of research tourism practical education helps the development of cultural tourism industry

Add ICO icon to clion MinGW compiled EXE file

事项研发工作流全面优化|Erda 2.2 版本如“七”而至

leetcode:1755. 最接近目标值的子序列和
随机推荐
Web Service简单入门示例
最长摆动序列[贪心练习]
XML建模
校招期间 准备面试算法岗位 该怎么做?
LeetCode_哈希表_困难_149. 直线上最多的点数
Sequence alignment
Influence of oscilloscope probe on measurement bandwidth
Clion configures Visual Studio (MSVC) and JOM multi-core compilation
The transformation based on vertx web sstore redis to realize the distributed session of vertx HTTP application
leetcode:1139. The largest square bounded by 1
MySQL ifnull usage function
Golang (1) | from environmental preparation to quick start
PHP deserialization +md5 collision
基于 Ingress Controller 在集群外访问 Zadig 自测环境(最佳实践)
学习机器人无从下手?带你体会当下机器人热门研究方向有哪些
Material design component - use bottomsheet to show extended content (II)
示波器探头对测量带宽的影响
Opérations de lecture et d'écriture pour easyexcel
Get JS of the previous day (timestamp conversion)
@Validated基础参数校验、分组参数验证和嵌套参数验证