Comments (4)
This problem seems to be a bug in the converter I used. As you said, I fixed the problem by modifying the output of yunet.py.
`
class YuDetectNet(nn.Module):
...
def forward(self, x):
self.img_size = x.shape[-2:]
feats = self.backbone(x)
outs = self.head(feats)
head_data=[(x.permute(0, 2, 3, 1).contiguous()) for x in outs]
head_data = torch.cat([o.view(o.size(0), -1) for o in head_data], dim=1)
head_data = head_data.view(head_data.size(0), -1, self.out_factor)
loc_data = head_data[:, :, 0 : 4 + self.num_landmarks * 2]
conf_data = head_data[:, :, -self.num_classes - 1 : -1]
iou_data = head_data[:,:, head_data.shape[2]-1:head_data.shape[2]]
m = torch.nn.Softmax(dim=2)
conf_data = m(conf_data)
output = (loc_data, conf_data, iou_data)
return output
...
`
The converter did not properly handle slices of indices containing negative numbers like head_data[:,:, -1:], so I modified it to slice with positive indices temporarily, bypassing the problem.
As a result, the converted tflite model worked well.
Thank you very much for your great help.
from libfacedetection.train.
Judging from the file name, I suppose you take this model face_detection_yunet_2022mar
from opencv zoo. The one in this repo is the latest version of YuNet, and the one in opencv zoo is old version but we will update soon.
I suggest you take a look at https://github.com/ShiqiYu/libfacedetection.train/blob/master/onnx/yunet_yunet_final_dynamic_simplify.onnx. It is the latest YuNet and has dynamic shape.
from libfacedetection.train.
As you said, using the yunet_yunet_final_dynamic_simplify.onnx model, I made a tflite model of the desired size.
However, an error occurs in the process of calculating the iou output during TFLite inference.
The reason is because of the strided_slice operation of TFLite. Below is a sample code written based on the yunet model for better understanding.
import tensorflow as tf
t = tf.constant([[[1, 1, 1], [2, 2, 2]],
[[3, 3, 3], [4, 4, 4]],
[[5, 5, 5], [6, 6, 6]]])
tf.strided_slice(
t,
begin=[0,0,-1],
end=[1,2,-1],
strides=[1,1,1],
begin_mask=2,
end_mask=2,
ellipsis_mask=0,
new_axis_mask=0,
shrink_axis_mask=0,
var=None,
name=None
)
result:
<tf.Tensor: shape=(1, 2, 0), dtype=int32, numpy=array([], shape=(1, 2, 0), dtype=int32)>
As a result of netron, it seems that shape=(1,2,1) should come out. As you can see, it is calculated as shape=(1, 2, 0) and no output is assigned.
Could you please review this issue? Could you make it like the output of the previous model?
Below is the last part of the converted tflite model graph.
ps.
This could be a problem with converting slice to tflite's stride_slice. However, there is no way to fix it. I really want to try yunet.
from libfacedetection.train.
I think you should file an issue on the repository of the convertion tool you used. As what I can see here, there is another possible solution: remove the slice part from the ONNX model.
So the slice nodes in the ONNX model come from the following lines:
libfacedetection.train/model/yudet.py
Lines 49 to 56 in e5c4a24
Line 53 to line 55 correspond to the slice nodes in the ONNX model. You can comment out these lines, change the output and do some changes in export2onnx.py
to get your own ONNX model without slice nodes:
libfacedetection.train/export2onnx.py
Line 48 in e5c4a24
from libfacedetection.train.
Related Issues (20)
- 模型是否支持关键点输出 HOT 8
- 当转onnx的时候,验证pytorch模型推理和onnx推理时候出现问题 HOT 2
- Cannot download labelsv2 HOT 3
- nonsquare input size training and exporting HOT 1
- How to train with custom dataset by using the pretrained model? HOT 2
- where can we get datasets with key points to train Yunet?
- 最小像素点修改 HOT 1
- 图像预处理时的均值和方差为什么是[0,0,0]和[1,1,1] HOT 1
- 老师,如果在Win上配置了MMDET环境后,如何修改指令执行train.py呀? HOT 5
- Why can't I find the yunet_final.pth weight file HOT 2
- Did you try Focal loss, how about its performance ? HOT 1
- The problem has been solved
- Train on rotated images to improve landmarks. HOT 1
- pytrch2onnx convervsion issue HOT 2
- 训练完成导出C++部署不成功
- Problems installing the repo HOT 1
- Batch inference problem! HOT 1
- Not able to setup the training environment HOT 9
- 为啥数据不做归一化 HOT 1
- 带出onnx出错 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 libfacedetection.train.