gyq_ 发表于 2020-4-1 16:20
我的是直接转换pt文件。
D RKNN output shape(batchnormalize): (0 16 16 320)
D Process convolution_at_i ...
jefferyzhang 发表于 2020-4-1 16:26
确认pytorch是不是1.2版本,高了低了都不行。
在确认你这个pth模型用这个pytorch1.2是否可以读出来推理
...
gyq_ 发表于 2020-4-1 16:33
pytorch确认是1.2.0,模型也可以读出来推理
jefferyzhang 发表于 2020-4-1 16:37
试下这个beta版本:
rknn_toolkit v1.3.1 beta3:
jefferyzhang 发表于 2020-4-1 16:37
试下这个beta版本:
rknn_toolkit v1.3.1 beta3:
- import torch
- import torch.nn as nn
- import os
- import math
- import logging
- import torch.utils.model_zoo as model_zoo
- import math
- import numpy as np
- import cv2
- from rknn.api import RKNN
- import rknn.api
- import torchvision.models as models
- model = nn.Sequential(
- nn.ConvTranspose2d(
- in_channels=1280,
- out_channels=16,
- kernel_size=4,
- stride=2,
- padding=1,
- output_padding=0,
- bias=True),
- # nn.BatchNorm2d(16, momentum=0.1),
- nn.ReLU(inplace=True),
- nn.ConvTranspose2d(
- in_channels=16,
- out_channels=16,
- kernel_size=4,
- stride=2,
- padding=1,
- output_padding=0,
- bias=True),
- nn.BatchNorm2d(16, momentum=0.1),
- nn.ReLU(inplace=True),
- nn.ConvTranspose2d(
- in_channels=16,
- out_channels=16,
- kernel_size=4,
- stride=2,
- padding=1,
- output_padding=0,
- bias=True),
- nn.BatchNorm2d(16, momentum=0.1),
- nn.ReLU(inplace=True),
- )
- trace_model = torch.jit.trace(model, torch.Tensor(1, 1280, 16, 16))
- trace_model.save('test_error.pt')
- input_size_list = [[1280, 16, 16]]
- # Create RKNN object
- rknn = RKNN(verbose=True)
- print('--> Loading model')
- ret = rknn.load_pytorch(model='test_error.pt', input_size_list=input_size_list)
复制代码
jefferyzhang 发表于 2020-4-2 08:21
把模型和转换脚本打包上传百度网盘,然后发给我,我提一个bug给NPU部门
gyq_ 发表于 2020-4-2 09:15
链接: https://pan.baidu.com/s/1jGD54_j_n0o6dj-xF-8SCw 密码: wor0
jefferyzhang 发表于 2020-4-2 09:22
你的问题已经上报了。
楼主的问题楼主怎么不见了?
gyq_ 发表于 2020-4-2 09:51
还有一个问题,这里的反卷积是不是执行错了,正确的h,w应该是从16到32到64到128的,结果反过来缩小到2了 ...
- import torch
- import torch.nn as nn
- import cv2
- from rknn.api import RKNN
- #
- channels = 1280
- model = nn.Sequential(
- nn.Conv2d(
- 3, 32,
- kernel_size=4, stride=2,
- padding=1, dilation=1, bias=False),
- nn.Conv2d(
- 32, 32,
- kernel_size=4, stride=2,
- padding=1, dilation=1, bias=False),
- nn.Conv2d(
- 32, 32,
- kernel_size=4, stride=2,
- padding=1, dilation=1, bias=False),
- nn.Conv2d(
- 32, 32,
- kernel_size=4, stride=2,
- padding=1, dilation=1, bias=False),
- nn.Conv2d(
- 32, channels,
- kernel_size=4, stride=2,
- padding=1, dilation=1, bias=False),
- # 当ConvTranspose2d输入通道数不等于输出通道数是,在build过程中会出错
- # 加一层conv2D转换一下后就可以跑通了
- # nn.Conv2d(
- # channels, 16,
- # kernel_size=3, stride=1,
- # padding=1, dilation=1, bias=False),
- nn.ConvTranspose2d(
- in_channels=channels,
- # in_channels=16,
- out_channels=16,
- kernel_size=4,
- stride=2,
- padding=1,
- output_padding=0,
- bias=True),
- nn.BatchNorm2d(16, momentum=0.1),
- nn.ReLU(inplace=True),
- nn.ConvTranspose2d(
- in_channels=16,
- out_channels=16,
- kernel_size=4,
- stride=2,
- padding=1,
- output_padding=0,
- bias=False),
- nn.BatchNorm2d(16, momentum=0.1),
- nn.ReLU(inplace=True),
- nn.ConvTranspose2d(
- in_channels=16,
- out_channels=16,
- kernel_size=4,
- stride=2,
- padding=1,
- output_padding=0,
- bias=False),
- nn.BatchNorm2d(16, momentum=0.1),
- nn.ReLU(inplace=True),
- )
- # 保存为onnx
- torch.onnx.export(model,
- torch.Tensor(1, 3, 512, 512),
- 'test_error2.onnx',
- verbose=True,
- do_constant_folding=False, # 是否执行常量折叠优化
- input_names=["input"], # 输入名
- output_names=["output"], # 输出名
- )
- input_size_list = [[3, 512, 512]]
- # Create RKNN object
- rknn = RKNN(verbose=True)
- print('--> Loading model')
- ret = rknn.load_onnx(model='test_error2.onnx')
- print('--> building model')
- ret = rknn.build(do_quantization=True, dataset='dataset.txt')
- print('--> export model')
- ret = rknn.export_rknn('test_error2.rknn')
- ret = rknn.load_rknn('test_error2.rknn')
- img = cv2.imread('space_shuttle_512.jpg')
- ret = rknn.init_runtime()
- print('--> inference')
- outputs = rknn.inference(inputs=[img])
- print(outputs[0].shape)
复制代码
jefferyzhang 发表于 2020-4-2 09:54
这里看不出来,你可以按troubleshoot文档试着dump出每一层结果来看下是不是预期 ...
gyq_ 发表于 2020-4-3 14:26
我输出出来看过了,确实是和预期的相反。
刚刚我又试了一下把第一个反卷积层的输入通道和输出通道改成相 ...
jefferyzhang 发表于 2020-4-3 14:55
试下beta7:
链接:https://pan.baidu.com/s/1DuLeBawfoBP62mu0ADNGAA
提取码:qtys
欢迎光临 Toybrick (https://t.rock-chips.com/) | Powered by Discuz! X3.3 |