Comments (3)
我们提供的是pytorch保存的模型,onnx格式的模型可自通过我们开源的模型参数自行转换
from iim.
请问你转换成功了吗,可以看下转onnx的代码嘛
from iim.
这个是转换为onnx的代码,需要注意输入为13h*w
import os
from tkinter.messagebox import NO
import torch
import torch.onnx
import torch.nn as nn
import onnxruntime as ort
import numpy as np
import torch.nn.functional as F
from tqdm import tqdm
import onnx
from onnxsim import simplify
from model.locator import Crowd_locator
from collections import OrderedDict
# os.environ['CUDA_VISIBLE_DEVICES']= '1'
GPU_ID = '0'
os.environ["CUDA_VISIBLE_DEVICES"] = GPU_ID
torch.backends.cudnn.benchmark = True
def onnx_export(model_path):
net = Crowd_locator(netName,GPU_ID,pretrained=False)
net.cuda()
state_dict = torch.load(model_path)
if len(GPU_ID.split(',')) > 1:
net.load_state_dict(state_dict)
else:
new_state_dict = OrderedDict()
for k, v in state_dict.items():
name = k.replace('module.', '')
new_state_dict[name] = v
net.load_state_dict(new_state_dict)
net.eval()
# 打印模型的每一层名称
for name, module in net.named_modules():
print(name,'nnnnn')
dummpy_input = torch.zeros(1, 3, 512, 1024).cuda() # 640 640
# dummpy_input = torch.zeros(1, 3, 512, 1024).cuda()
onnx_name = 'HRnet_Crowd_count_512_1024_opset12.onnx'
# net = net(dummpy_input)
torch.onnx.export(
net, dummpy_input, onnx_name,
verbose=True,
input_names=['image'],
output_names=['predict'],
opset_version=12,
dynamic_axes=None
)
def onnx_sim(onnx_path):
model_onnx = onnx.load_model(onnx_path)
model_smi, check = simplify(model_onnx)
save_path = 'HRnet_Crowd_count_512_1024_opset12-sim.onnx'
onnx.save(model_smi, save_path)
print('模型静态图简化完成')
if name == 'main':
netName = 'HR_Net' # VGG16_FPN HR_Net
model_path = '/IIM/Preweights/NWPU-HR-ep_241_F1_0.802_Pre_0.841_Rec_0.766_mae_55.6_mse_330.9.pth'
onnx_path = '/IIM/Preweights/1024_HRnet_Crowd_count_512_1024_opset12.onnx'
# save_model(pth_file)
onnx_export(model_path)
# onnx_sim(onnx_path)
print('Done')
from iim.
Related Issues (20)
- 我在training時遇到以下錯誤 HOT 1
- 训练时有足够内存,依然得到out of memory问题 HOT 1
- 训练时有足够得内存,依然得到out of memory问题
- 模型保存为pt时报错RuntimeError: Could not export Python function call 'BinarizedF' HOT 1
- Great work but Threshold Encoder module is useless.Details look at the picture HOT 3
- How to visualize other datasets test set pictures? HOT 7
- threshold appear to be nan during the training process HOT 2
- RuntimeError: CUDA error: out of memory CUDA kernel errors might be asynchronously reported at some other API call,so the stacktrace below might be incorrect. For debugging consider passing CUDA_LAUNCH_BLOCKING=1. HOT 1
- How to config to train on NVIDIA GeForce RTX 3090 Ti/PCIe/SSE2 HOT 6
- Training on general dataset HOT 2
- Could you please give me demo code, I mean real-time testing code?
- Memory allocation error HOT 1
- Confidence level? HOT 8
- 主页给的HRNet权重链接hrnetv2_w48_imagenet_pretrained.pth和Crowd_locator中模型结构不太一样 HOT 1
- 请问mask_50_60具体有什么作用?运行prepare_NWPU会出现jsons文件缺失错误(缺失的是测试图片的id,所以肯定是没有的) HOT 1
- 您好 我想问下每个数据集给出的mean_std是如何计算的,和我自己计算的结果不太相同。
- segfault with pytorch 1.17 and 2.0.0 HOT 1
- FileNotFoundError: [Errno 2] No such file or directory: '../ProcessedData/JHU\\train.txt'
- input video HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from iim.