pytorch模型转keras模型

实验环境:

pytorch1.3.1

tensorflow1.4.0

keras2.3.1

onnx1.6.0

onnx2keras0.0.17

pytorch2keras0.2.3

安装pytorch2keras时提示tensorflow版本过低,可以不用管,如果安装时将tensorflow自动卸载并安装tensorflow2.0.0版本,可以将tensorflow装回原版本,不影响程序运行。

转换代码

# @Author: ---chenzhenhua
# @E-mail: [email protected]

import numpy as np
import torch
from torch.autograd import Variable
from pytorch2keras.converter import pytorch_to_keras
import torchvision.models as models

input_np = np.random.uniform(0, 1, (1, 3, 224, 224))
print(input_np.shape)
input_var = Variable(torch.FloatTensor(input_np))
print(input_var.shape)
model = models.resnet18()
k_model = pytorch_to_keras(model, input_var, [(3, 224, 224,)], verbose=True, change_ordering=True)
k_model.summary()
发布了19 篇原创文章 · 获赞 3 · 访问量 412

猜你喜欢

转载自blog.csdn.net/u011740601/article/details/103520120
今日推荐