Comments (7)
That's a good question.
Because tensorflow convolution padding is inconsistent with pytorch, tensorflow 'SAME' padding may pad more pixels on the right than left.
You can see https://stackoverflow.com/questions/52975843/comparing-conv2d-with-padding-between-tensorflow-and-pytorch.
If you get a good to fix this problem, welcome PR.
from onnx2tflite.
thanks, may be solved with some trick.
from onnx2tflite.
Hi
I do some tests.
because network has many 3x3 conv with same padding.
I change the code with below code on mobileone. it can reduce many pad and get the same result, reduce the peak of mobile running time. so we can use this trick^^.
if pads is not None and max(pads) == 1 and max(strides) == 1:
self.conv = keras.layers.DepthwiseConv2D(
kernel_size, strides, "SAME", use_bias=False if bias is None else True,
weights=[weights] if bias is None else [weights, bias],
dilation_rate=dilations,
activation=None,
kernel_initializer='zeros',
bias_initializer='zeros'
)
self.pad =None
from onnx2tflite.
Hi I do some tests. because network has many 3x3 conv with same padding. I change the code with below code on mobileone. it can reduce many pad and get the same result, reduce the peak of mobile running time. so we can use this trick^^.
if pads is not None and max(pads) == 1 and max(strides) == 1: self.conv = keras.layers.DepthwiseConv2D( kernel_size, strides, "SAME", use_bias=False if bias is None else True, weights=[weights] if bias is None else [weights, bias], dilation_rate=dilations, activation=None, kernel_initializer='zeros', bias_initializer='zeros' ) self.pad =None
Nice idea, thanks for your test.
Can you evaluate it on other types of convolution, such as keras.layers.Conv2D and keras.layers.Conv2DTranspose.
It's pleasure for your PR.
from onnx2tflite.
DepthwiseConv2D should be Consistent with Conv2D. As to Conv2DTranspose, it need to be tested.
from onnx2tflite.
Thanks for your nice work again, I will test it as soon~
from onnx2tflite.
I was tested it on this model.
Your trick is work well for conv\depthwise conv\group conv, but not with ConvTranspose, thanks for your contribution again.
import torch
import torch.nn as nn
class testmodel(nn.Module):
def __init__(self) -> None:
super(testmodel, self).__init__()
self.conv1 = nn.Conv2d(3, 6, 3, 2, 1)
self.conv2 = nn.Conv2d(3, 6, 3, 1, 1)
self.depthwiseConv1 = nn.Conv2d(3, 6, 3, 2, 1, groups=3)
self.depthwiseConv2 = nn.Conv2d(3, 6, 3, 1, 1, groups=3)
self.convTranspose1 = nn.ConvTranspose2d(6, 3, 2, 2, 0)
self.convTranspose2 = nn.ConvTranspose2d(6, 30, 2, 2, 0)
self.group_conv1 = nn.Conv2d(30, 30, 3, 1, 1, groups=30)
def forward(self, X):
x1 = self.conv1(X)
x2 = self.conv2(X)
x3 = self.depthwiseConv1(X)
x4 = self.depthwiseConv2(X)
x5 = self.convTranspose1(x1)
x6 = self.convTranspose1(x3)
out = x2+x4+torch.cat((x5, x6), dim=1)
out = self.convTranspose2(out)
out = self.group_conv1(out)
return out
model = testmodel()
X = torch.randn(1, 3, 224, 224)
torch.onnx.export(model, X, './models/opt_test.onnx', opset_version=12)
from onnx2tflite.
Related Issues (20)
- KeyError: 'NonMaxSuppression not implemented yet' (YOLOv7 tiny onnx to tflite) HOT 2
- Dimensional error HOT 3
- Add option to allow for dynamic resize HOT 4
- ValueError: Layer p_re_lu weight shape (1, 1, 32) is not compatible with provided weight shape (32, 1, 1). HOT 3
- Extract score and class_id from converted model HOT 6
- Add setup.py to be installed as a package HOT 2
- Opencv resize method use different axises, which leads to errors during int8 callibration
- onnx converting to tflite got an error, is there any solutions? HOT 3
- max error is too big during conversion HOT 2
- dimension error
- Convert fail Cannot reshape a tensor HOT 1
- yolov5s.onnx转换tflite出错 HOT 2
- Unable to perform 1dconv conversion? HOT 1
- The gpu cannot be used after model conversion HOT 1
- onnx转为tflite 为啥数据类型变成了uint8? HOT 1
- 模型转换缺少conv3d算子 HOT 3
- 报错
- 模型转换报错 HOT 2
- onnx转tflite 如何让维度保持不变 HOT 1
- ValueError: Unrecognized keyword arguments passed to Conv2D: {'weights': [array([[[[-0.16197614, HOT 2
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 onnx2tflite.