PROGrand/yolo-coreml

Question:Custom dataset with converter_v4_old.py

Closed this issue · 8 comments

Dear PROGrand

I am trying to cover the model with converter_v4_old.py with custom dataset.
I can successfully detect with 608x608 and 80 classses pretrained coco-data set(yolov4.cfg/yolov4.weight) in Xcode project.
I tried the 960x960 and 22 classes with custom pertained dataset which can detect your test.py or others. And convert seems to be succeeded.
In Xcode,
Input :Image (Color 960 × 960)
Output3:MultiArray (Float32 81 × 120 × 120)
Output2:MultiArray (Float32 81 × 60 × 60)
Output1:MultiArray (Float32 81 × 30 × 30)
Using the same Xcode project, I cannot detect any object.

Could you provide any suggestion?

Sorry for several question.

Are you modified anchors and labels parts of xcode example according to your custom network?
Modern converter_v4.py incorporates anchors and labels in mlpackage info, but old example needs to be adopted with objective-c and swift.

Dear PROGrand

I had modified the labels and anchors in Helper.swift
anchors is
[142,110, 192,243, 459,401], [36,75, 76,55, 72,146], [12,16, 19,36, 40,28]
which is the YOLOv4 original number.

And in YOLO.swift
I modified as followings
**
public static let inputWidth = 960
public static let inputHeight = 960

let numClasses = 22

let gridHeight = [30, 60, 120]
let gridWidth = [30, 60, 120]
**
Tracing the data of tc
let tc = Float(featurePointer[offset(channel + 4, cx, cy)])
always tc value is negative value, so after sigmoid conversion , mostly zero.

New converter of MLpackages, as I mentioned with other sled, I cannot convert the data.

Now I am stuck.

Without knowledge of your network it is not easy to answer.
Can you provide cfg, weights and png with detectable object?

Dear PROGrand

Thank for your support.
I will send the cfg and weights, png file, but png image content is slightly confidential, so I would like to send you directly. Can you inform the e-mail address? or somewhere cloud which I can access.

Dear PROGrand

I sent the cfg, weights, and jpg file today to your address.

Ok, i tested your network. Your model is too large for MIL format and produces out-of-memory errors on my iphone 12, so the only way to convert it to neuralnetwork using new script convert_v4_network.py. Also i added additional unsupported training tag to prepare script, so update it on your side.
What i have now - mlmodel file and about one good detection per 3-4 second on iPhone 12. First time mlmodel loading very slow after application installation (tens of seconds), but further app launches loaded faster.
I use new app.
I just point iphone camera to computer monitor with your test jpeg opened and have detections probs near 1.0.
In case of conversion problems just check your anaconda setup. I repeated the installation steps multiple times on different macos and wsl machines and all works as expected.

This is blurred iphone screenshot:
detection

Dear PROGrand

Thanks for your great support. Today I succeeded to convert using convert_v4_network.py w/o any error, and detect my object with 960x960.

I found 3 things during my testing.
1)Coremltools 5.1.0 just supported MacOS 10.15 or higher. So I updated the MacOS to 10.15. then no failure found during conversion.
10.14 or earlier version of MacOS, we need to use coremltools 4.1
2)Now Anaconda is not free in case of some situation, so I used miniconda3-py37_4.10.3-MacOSX-x86_64.pkg. In this condition with MacOS10.15, I can convert also.
3)During pip installation of tensoflow==2.5.0, h5py was automatically replaced to 3.1.0. So h5py install condition will be 3.1.0

I think MacOS version information and h5py info update in your README.md will be helpful for beginner like me.

Finally thank for your great help.