-
-
Notifications
You must be signed in to change notification settings - Fork 16k
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
Hello, how do I change the dimensions of the output structure, #12639
Comments
👋 Hello @yuqilol, thank you for your interest in YOLOv5 🚀! Please visit our ⭐️ Tutorials to get started, where you can find quickstart guides for simple tasks like Custom Data Training all the way to advanced concepts like Hyperparameter Evolution. If this is a 🐛 Bug Report, please provide a minimum reproducible example to help us debug it. If this is a custom training ❓ Question, please provide as much information as possible, including dataset image examples and training logs, and verify you are following our Tips for Best Training Results. RequirementsPython>=3.8.0 with all requirements.txt installed including PyTorch>=1.8. To get started: git clone https://github.com/ultralytics/yolov5 # clone
cd yolov5
pip install -r requirements.txt # install EnvironmentsYOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):
StatusIf this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training, validation, inference, export and benchmarks on macOS, Windows, and Ubuntu every 24 hours and on every commit. Introducing YOLOv8 🚀We're excited to announce the launch of our latest state-of-the-art (SOTA) object detection model for 2023 - YOLOv8 🚀! Designed to be fast, accurate, and easy to use, YOLOv8 is an ideal choice for a wide range of object detection, image segmentation and image classification tasks. With YOLOv8, you'll be able to quickly and accurately detect objects in real-time, streamline your workflows, and achieve new levels of accuracy in your projects. Check out our YOLOv8 Docs for details and get started with: pip install ultralytics |
@yuqilol hello! It's great to see you're working on deploying YOLOv5 on Android. To modify the output structure for TFLite compatibility, you can indeed add a reshape operation at the end of your model. However, the code snippet you provided seems incomplete. For a reshape operation in PyTorch, you would typically use class ReshapeOutput(nn.Module):
def __init__(self, *shape):
super().__init__()
self.shape = shape
def forward(self, x):
return x.view(-1, *self.shape) # or torch.reshape(x, (-1, *self.shape)) You can then instantiate this layer with the desired output shape and add it to your model's If you encounter any errors, please provide the specific error messages, and we can troubleshoot further. For more detailed guidance, you can refer to our documentation at https://docs.ultralytics.com/yolov5/. Keep in mind that changing the model's architecture might require retraining for optimal performance. Good luck with your deployment! 🚀 |
Hello, I used your structure, but when I used summary to view the structure, the following error occurred. I guess it was a mistake in my yaml file. The error is as follows:
0 -1 1 3520 models.common.Conv [3, 32, 6, 2, 2] Fusing layers... The above exception was the direct cause of the following exception: Traceback (most recent call last): [-1, 1, Conv, [256, 1, 1]], [-1, 1, Conv, [256, 3, 2]], [-1, 1, Conv, [512, 3, 2]], [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) |
Hello @yuqilol, it looks like you're on the right track with adding the reshape layer to your First, ensure that the Secondly, the way you've added the Lastly, the If you continue to experience issues, please provide the full error message, and I'll be happy to help you troubleshoot further. Remember, the error message is key to understanding what might be going wrong. Keep up the good work! 🛠️ |
hyperparameters: lr0=0.01, lrf=0.01, momentum=0.937, weight_decay=0.0005, warmup_epochs=3.0, warmup_momentum=0.8, warmup_bias_lr=0.1, box=0.05, cls=0.5, cls_pw=1.0, obj=1.0, obj_pw=1.0, iou_t=0.2, anchor_t=4.0, fl_gamma=0.0, hsv_h=0.015, hsv_s=0.7, hsv_v=0.4, degrees=0.0, translate=0.1, scale=0.5, shear=0.0, perspective=0.0, flipud=0.0, fliplr=0.5, mosaic=1.0, mixup=0.0, copy_paste=0.0
0 -1 1 3520 models.common.Conv [3, 32, 6, 2, 2] Transferred 348/349 items from yolov5s.pt |
DetectionModel( |
Hello @yuqilol, From the error message and the model structure you've provided, it seems that the The error Here are a few steps to troubleshoot the issue:
Since the error message indicates an issue with the If you continue to face issues, consider providing more context or the specific part of the code where the error occurs, so we can help you more effectively. |
Hello again @yuqilol, It seems you've decided not to modify the model structure due to the absence of a TPU on your device and are now looking into NPU support and output discrepancies between TFLite and CoreML models. Regarding NPU support, this is highly dependent on the specific hardware and software stack you are using. If the NPU has specific requirements or a dedicated SDK/API for model deployment, you would need to follow the manufacturer's guidelines for optimizing and deploying your model to leverage the NPU. As for the differences in output between TFLite and CoreML, this could be due to a variety of factors, including differences in how the models are quantized, optimized, or even how the post-processing is handled in each framework. To address this, you would typically:
Unfortunately, without specific details on the output differences and the exact code used for inference, it's challenging to provide a precise solution. If you believe there's an issue with the TFLite conversion process within the YOLOv5 repository, please provide detailed information on the steps you've taken, the expected output, and the actual output you're observing. For now, I would recommend reviewing the export and inference scripts for TFLite to ensure they align with your requirements and the expected output format. If there's a post-processing step that's not being applied correctly in the TFLite model, you might need to adjust the export script or the inference code to match the CoreML model's behavior. If you continue to encounter issues, please provide more detailed information or consider opening an issue in the YOLOv5 repository with all the necessary details for further assistance. |
Thank you for your answer, I have solved the problem. The first solution is to convert yolo's export.py into onnx, and then convert onnx into tflite. During this process, I made three mistakes. Second, I did not choose an environment with gpu when exporting, resulting in the weight could not be loaded on the graphics card. Third, our Android engineer enabled the npu interface and squeezed out the gpu interface, but npu was not called. The second solution is to export tflite using yolo's export.py. After my test, I found that tflite maps data from 0-640 to 0-1, which is not explained in the documents of yolo and tflite. |
Requirements: |
I'm glad to hear that you've resolved the problem, @yuqilol! It sounds like you encountered a few challenges along the way, but it's great that you were able to navigate through them. For future reference and for others who might encounter similar issues:
Your experience highlights the importance of a thorough understanding of the entire model conversion and deployment pipeline. Thank you for sharing your solutions, and best of luck with your project on Android! If you have any more questions or run into further issues, feel free to reach out. Happy coding! 🚀 |
👋 Hello there! We wanted to give you a friendly reminder that this issue has not had any recent activity and may be closed soon, but don't worry - you can always reopen it if needed. If you still have any questions or concerns, please feel free to let us know how we can help. For additional resources and information, please see the links below:
Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed! Thank you for your contributions to YOLO 🚀 and Vision AI ⭐ |
Search before asking
Question
Our project needs to be deployed on Android, so we converted to a tflite model, but the interface of the tflite task library only accepts 2D or 4D output structure, how can I change my model? At present, I have tried two schemes. First, I can change the output structure in detect, train the output for 4d, and then convert it. However, I failed to convert it, and there were many errors. The second is to add a reshape operator to the end of the yaml file of the model, but I don't know how to write this reshape operator and will always report an error.
Additional
class reshape_output(nn.Module):
# Concatenate a list of tensors along dimension
def init(self, c1,c2):
super().init()
def forward(self, x):
return torch.unsqueeze(x,-1)
The text was updated successfully, but these errors were encountered: