caffe2与pytorch计算速度比较

说明

caffe2 是读取的onnx模型,pytorch是加载的原始pth模型

测试结果

模型:mobilenet-v2

devicecaffe2pytorch
cuda90ms8ms
cpu24ms10ms

附caffe2推理代码

import onnx
import datetime
# Load the ONNX model
model = onnx.load("model/mobilenet-v2_100.onnx")

# Check that the IR is well formed
onnx.checker.check_model(model)

# Print a human readable representation of the graph
onnx.helper.printable_graph(model.graph, 'graph.txt')

# ...continuing from above
import caffe2.python.onnx.backend as backend
import numpy as np

rep = backend.prepare(model, device="CPU") # or "CPU"
# For the Caffe2 backend:
#     rep.predict_net is the Caffe2 protobuf for the network
#     rep.workspace is the Caffe2 workspace for the network
#       (see the class caffe2.python.onnx.backend.Workspace)

for i in range(100):
	begin = datetime.datetime.now()
	outputs = rep.run(np.random.randn(1, 3, 128, 128).astype(np.float32))
	end = datetime.datetime.now()
	k = (end - begin).microseconds
	print(k/1000)
# To run networks with more than one input, pass a tuple
# rather than a single numpy ndarray.
print(outputs[0])
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值