Working with YoloV5 exporting to pytorch.hub.load , and trouble converting to h5/.keras

25 Views Asked by At

My workflow is as follows:
I following the information in https://docs.ultralytics.com/yolov5/tutorials/train_custom_data/#3-select-a-model using the yolov5n.pt model.

  1. Create a data set with png files label,

  2. bounding boxes the files with the QT labeler that normalizes the information of the bounding boxes

  3. Create train(80%) val(10%) test(10%) directories, sort files accordingly create the required yaml file with the number of classes

  4. I have trained a image classifier model using Yolov5n. Because it is going on an edge device. It saves the final run as best.pt, it tells me that I have 157 layers and 1million + parameters no gradient.

  5. Immediately afterward and I have been able to export those files as onnx, pb, and saved_model. Then, I have used torch.hub.load('path/to/hubconf.py', 'custom', model_name = 'path/to/custom/model' , source='local') .
    But after that I run into difficulties. I load the saved_model using tf.keras.models.load_model() The pb and saved models are loaded as _UserObject and therefore have no summary or the detectmodelbackend is empty. But when I manually read the Graph_def as a .pb then I can see the nodes. ALso, when I print the pytorch model it gives the layers back. At this point I am not even concerned with accuracy. I just need to load a model any type then convert it to a keras (.h5) format. It must be in that format. I have read over this crypt information from https://www.tensorflow.org/tutorials/keras/save_and_load. I have tried this Convert onnx model to keras and https://medium.com/analytics-vidhya/pytorch-to-keras-using-onnx-71d98258ad76 My questions are is there a step I am missing to either convert when loading the pytorch? Is there a problem with my training work flow? Do I need to use autoshape or the yolov5s model? Do I need to select a gradient? Again I am not concerned at the accuracy of the model as opposed to converting it into the h5 format. Thank you in advance for any information that you can provide,

0

There are 0 best solutions below