WongKinYiu / yolov7

Implementation of paper - YOLOv7: Trainable bag-of-freebies sets new state-of-the-art for real-time object detectors
GNU General Public License v3.0
13.22k stars 4.17k forks source link

Convert Yolo-Pose to coreml #1266

Open diegogranziol opened 1 year ago

diegogranziol commented 1 year ago

I would really like to convert https://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7-w6-pose.pt to CoreML but the output is incorrect. Essentially the model.model[-1].export = True, removes the 0th output which is what is used for predictions in https://github.com/WongKinYiu/yolov7/blob/main/tools/keypoint.ipynb. I have attempted some work arounds that have all met with failure.

For example, this is a work around

`

Wrap the Model to Allow Tracing*

from torch import nn class WrappedYolo(nn.Module):

def __init__(self):
    super(WrappedYolo, self).__init__()
    self.model = model.eval()

def forward(self, x):
    res = self.model(x)
    x = res[0]
    return x

Trace the Wrapped Model

traceable_model = WrappedYolo().eval() trace = torch.jit.trace(traceable_model, tensor_new) ct_model = ct.convert(trace, inputs=[ct.ImageType('image', shape=(640,640), scale=1 / 255.0, bias=[0, 0, 0])])

ValueError: Core ML only supports tensors with rank <= 5. Layer "model.model.118.anchor_grid", with type "const", outputs a rank 6 tensor.

Razamalik4497 commented 1 year ago

Hello, did you resolve the issue?

diegogranziol commented 1 year ago

Hello @Razamalik4497, this model cannot be converted to CoreML. Even what you do manage ends up being complete garbage. Try the set of models on mmpose.

Razamalik4497 commented 1 year ago

Thanks for a quick response, I just starting research on it if I found something related I will share with.

I believe you have searched a lot about it, I just trying myself.

You are right I will use either mmpose or movenet then.

On Mon, Feb 20, 2023, 4:56 PM Diego Granziol @.***> wrote:

Hello @Razamalik4497 https://github.com/Razamalik4497, this model cannot be converted to CoreML. Even what you do manage ends up being complete garbage. Try the set of models on mmpose.

— Reply to this email directly, view it on GitHub https://github.com/WongKinYiu/yolov7/issues/1266#issuecomment-1436856617, or unsubscribe https://github.com/notifications/unsubscribe-auth/AL3THUM4TM7ABLZKFSGX45LWYNLVLANCNFSM6AAAAAATCOKQKE . You are receiving this because you were mentioned.Message ID: @.***>