YOLOv7 save_model load_model tensorflow

Hi all,

I start to work on some projects for image classification,localization with TensorFlow.

I am using YOLOv7 from here GitHub - WongKinYiu/yolov7: Implementation of paper - YOLOv7: Trainable bag-of-freebies sets new state-of-the-art for real-time object detectors.

I was able to train model on my own dinosaurs dataset and it works fine.

Weights are saved in format .pt

Is there any possibility to have this model save like this when I was using just model.save_model and then load_model:

├── saved_model
│ │ ├── assets
│ │ ├── saved_model.pb
│ │ ├── variables
│ │ ├── variables.data-00000-of-00001
│ │ └── variables.index

Thanks for any advice.


If someone interested I was able to do it by converting this model to onnx:

!python export.py --weights cfg/deploy/yolov7.pt --include torchscript onnx

and then to tensorflow:

onnx_model = onnx.load(“/content/drive/MyDrive/yolo7/yolov7/cfg/deploy/yolov7.onnx”) # load onnx model
tf_rep = prepare(onnx_model) # prepare tf representation

But even if it was in desired structure I was not able to use this model properly.
Then I found that you can load model through torch :

model = torch.hub.load(‘WongKinYiu/yolov7’,‘custom’,‘/content/drive/MyDrive/yolo7/yolov7/runs/train/yolov7-dino4/weights/best.pt’,force_reload=‘True’)

and then use it like :
img =model(filename)