Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GSoC] Little help on GSoC 2023 Pre-requisite task #917

Closed
adrianboguszewski opened this issue Mar 15, 2023 · 3 comments
Closed

[GSoC] Little help on GSoC 2023 Pre-requisite task #917

adrianboguszewski opened this issue Mar 15, 2023 · 3 comments
Labels
gsoc Google Summer of Code (Prerequisite Task)

Comments

@adrianboguszewski
Copy link
Contributor

Discussed in openvinotoolkit/openvino#16294

Originally posted by Matrixmang0 March 14, 2023
Hello world!

My name is Santhosh, and I am an undergrad junior Electrical and Electronics Engineering from India.

I would really rooting to work on OpenVINO projet, this summer. So, I am currently working on my GSOC pre-requisite task on Optimizing YOWOv2 model using OpenVINO. I am actually stuck at Converting the model to ONNX format, dealing with an error. Below is the code snippet, where I am facing the follwing error.

import os

# Define the path to the weights
weights_path = Path('model/yowo_v2_tiny_ava.pth')

# Define the path where the ONNX model will be saved
onnx_path = weights_path.with_suffix('.onnx')

# Define the width and height of the input image and the number of frames in the input video
IMAGE_WIDTH = 208
IMAGE_HEIGHT = 208
NUM_FRAMES = 16

# If an ONNX model with the same name already exists, remove it
if os.path.exists(onnx_path):
    os.remove(onnx_path)

# Create a dummy input tensor for the PyTorch model, with random values
dummy_input = torch.randn(1, 3, NUM_FRAMES, IMAGE_HEIGHT, IMAGE_WIDTH)

# Export the PyTorch model to ONNX format using the `torch.onnx.export()` function
torch.onnx.export(
    YOWO_model,           # The PyTorch model to export
    dummy_input,             # The dummy input tensor to use for tracing
    onnx_path,                  # The path to save the ONNX model
    verbose=False,       
    opset_version=12,     
    input_names=['input'],
    output_names=['output'], 
    dynamic_axes={       
    'input': {0: 'batch_size', 2: 'seq_length'},
    'output': {0: 'batch_size', 2: 'seq_length'}
    }
)

# Load the exported ONNX model 
onnx_model = onnx.load(onnx_path)

# Save the ONNX model 
onnx.save(onnx_model, onnx_path)

print(f"ONNX model exported to {onnx_path}.")

Error for the code!

File ~/Openvino-projects/openvino_notebooks/notebooks/YOWOv2-optimization/YOWOv2/models/backbone/backbone_2d/cnn_2d/yolo_free/yolo_free_fpn.py:204, in PaFPNELAN.forward(self, features)
    202 c6 = self.cv1(c5)
    203 c7 = F.interpolate(c6, scale_factor=2.0)
--> 204 c8 = torch.cat([c7, self.cv2(c4)], dim=1)
    205 c9 = self.head_elan_1(c8)
    206 ## P4 -> P3

RuntimeError: Sizes of tensors must match except in dimension 1. Expected size 12 but got size 13 for tensor number 1 in the list.

This is just the final trace of the error, as the entire error log is real huge

Any help on this would really be appreciated!

@adrianboguszewski adrianboguszewski added the gsoc Google Summer of Code (Prerequisite Task) label Mar 15, 2023
@adrianboguszewski adrianboguszewski transferred this issue from openvinotoolkit/openvino Mar 15, 2023
@adrianboguszewski
Copy link
Contributor Author

@Matrixmang0, transferred here as related to the prerequisite task.

@blaz-r
Copy link
Contributor

blaz-r commented Mar 19, 2023

@Matrixmang0 hello, just to make sure, does inference in PyTorch format work for you? I don't see any code on your repo regarding yowov2 and from above I'm not sure if that works. I'd say that if you didn't try that, it'd be great to verify the inference of the original model first, and then possibly check the dimensions with debugger, because it might be something with that.

@adrianboguszewski
Copy link
Contributor Author

Closing because of the lack of activity. Please reopen if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gsoc Google Summer of Code (Prerequisite Task)
Projects
None yet
Development

No branches or pull requests

2 participants