Closed hoseinhamzei closed 1 year ago
Export to Tensorflow is a work in progress. See #209 for progress.
@hoseinhamzei @knoppmyth we don't have tf.js export currently, but we do have TF and TFLite FP32 and FP16 export working correctly, i.e.
yolo export model=yolov8n.pt format=tflite
If you have TF expertise please consider helping out with TF.js exports. Thank you!
👋 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 ⭐
hi @glenn-jocher I can see tfjs is now supported. any change the output will be the same as yolov5? with nms + agnostic , as [bbox, scores, labels, numDetections] ) https://github.com/ultralytics/yolov5/blob/5ca8e822c8e75cde1d613dea8bfa49009fdc3618/export.py#L457
for now, its looks like there are no nms and the output is Identity:0
here https://github.com/ultralytics/ultralytics/blob/701fba47700dee7a6bd8ff4d219eca91adc9d3be/ultralytics/yolo/engine/exporter.py#L652
if not is it possible to get some clarification on the model output? the output shape looks like bbox[4] + score[1] + one hot encoder [len(classes)] is the 4bbox in format xyxy or xywh? is the score right after the bbox?
Thanks
@mbenami we're using onnx2tf for all TF exports now, so we have a more scalable export solution that doesn't require us to maintain and build TF modules/models for exports, but it also means that we haven't reproduced all of the added export features in YOLOv5 either. If you'd like to help contribute please submit a PR! Thank you!
@glenn-jocher thanks for now, I convert the output on my side
for everyone else that needs some clarification on the tfjs
output
batch, [x_center, y_center, width, height, prob_class0, prob_class1, ..., prob_class_N], number of results per model type (anchors)
👋 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 ⭐
Hi i got onnx model from export code then i run this code: https://colab.research.google.com/drive/1ek5gT3wXdXVs95Bs0_EIyOf-gwa0_a3c?usp=sharing and got tfjs files :)
@FatemeZamanian hi there,
I'm glad to hear that you were able to successfully convert your YOLOv8 model to tfjs using the provided code in the Colab notebook. This indicates that the export process was successful and you now have the necessary tfjs files.
If you have any further questions or need assistance with anything else related to YOLOv8, please feel free to ask.
I have created an object detection model, where my input is (1, 3, 224, 224) and the output is (1, 7, 1029). It works perfectly when using YOLO. However, when I export it to TensorFlow.js, I have no idea how to transform the output (1, 7, 1029) into bounding boxes. Can someone help me?"
In this request, the user explains that they have created an object detection model that takes input of shape (1, 3, 224, 224) and produces output of shape (1, 7, 1029). The model performs well when using the YOLO framework. However, they are facing difficulties in transforming the output tensor into bounding boxes when exporting the model to TensorFlow.js. They are seeking assistance to handle this issue.
@VictorBarbosa the output tensor shape of (1, 7, 1029) in your TensorFlow.js model represents the model's prediction outputs grid with the size of 7x7. Each cell in the grid is responsible for predicting an object within that cell. The tensor contains the following parameters for each cell:
To extract the bounding boxes from the output tensor, you would need to apply some post-processing steps, including applying an objectness score threshold and non-maximum suppression (NMS) for handling overlapping boxes.
The exact implementation can vary across different projects and use-cases, so you may need to adjust these steps according to your needs.
@glenn-jocher Thank you ,
@VictorBarbosa you're welcome! If you have any more questions or need further assistance, don't hesitate to ask. Happy coding!
When I am trying to convert the trained yolov8 model to ( !yolo export model="/content/drive/MyDrive/PPE_Detection_YOLOV8/dataset/runs/detect/train/weights/best.pt" format= tfjs) its only giving this "best_saved_model" but I want "best_web_model" in the tutorial iam following one they run the code they got best_web_model. can you help me with this guys
@Smith-S-S it appears that you are encountering an issue with exporting a YOLOv8 model to TensorFlow.js (tfjs) format. The error message indicates that the export to the intermediate .pb
(Protocol Buffers) format is failing, which is a necessary step before converting the model to TensorFlow.js format.
The error '_UserObject' object has no attribute 'inputs'
suggests that there might be an issue with the model object or the export process that is not correctly handling the model's input layer.
To troubleshoot this issue, please follow these steps:
Ensure that you have the latest version of the required libraries installed. In Google Colab, you can install or upgrade libraries using !pip install
or !pip install --upgrade
.
Make sure that the model you are trying to export is compatible with TensorFlow.js. Some model architectures or custom layers might not be directly convertible.
Try exporting the model to a different format first, such as ONNX or TensorFlow SavedModel, to see if the issue is specific to TensorFlow.js. If the export to these formats is successful, it might indicate a problem with the TensorFlow.js conversion process.
If the issue persists, consider opening an issue on the Ultralytics YOLOv8 GitHub repository with detailed information about the error and the steps you've taken. The maintainers or the community might be able to provide more specific guidance or a fix.
As a workaround, you can try using a different model that has been successfully exported to TensorFlow.js by others, or you can attempt to modify the model architecture to remove any unsupported layers or operations.
Remember that exporting models to different formats can sometimes be challenging due to compatibility issues between different frameworks and libraries. It often requires trial and error to resolve these issues.
Sure sir I try now this thing and come to you sir
this was my full code, sir drive.mount("/content/drive") %cd "/content/drive/MyDrive/PPE_Detection_YOLOV8"
!pip install roboflow from roboflow import Roboflow rf = Roboflow(api_key="R38i0N5gBDDkzbmApwoO") project = rf.workspace("aabbcceeffgg").project("brain-tumor-detection-69d9s") dataset = project.version(2).download("yolov5")
!yolo task=detect model=yolov8n.pt data="/content/drive/MyDrive/PPE_Detection_YOLOV8/dataset/Brain-Tumor-Detection-2/data.yaml" epochs=170 imgsz=640
!pip install ultralytics !pip install tensorflow==2.13.0 !yolo export model="/content/drive/MyDrive/PPE_Detection_YOLOV8/dataset/runs/detect/train/weights/best.pt" format= tfjs
But for me getting the only one file it is "best_saved_model" and in side I have
so now what can I do to get that "best_web_model" sir?
I got it sir thank u
@Smith-S-S it appears that you are encountering an issue with exporting a YOLOv8 model to TensorFlow.js (tfjs) format. The error message indicates that the export to the .pb
(Protocol Buffers) format is failing, which is a prerequisite step before converting to TensorFlow.js format.
The error '_UserObject' object has no attribute 'inputs'
suggests that there might be an issue with the model object or the export process that is not correctly handling the model's inputs.
To resolve this issue, please ensure that you are using the latest version of YOLOv8 and all its dependencies. If you are already using the latest version, this might be a bug that needs to be reported to the Ultralytics YOLOv8 GitHub repository.
In the meantime, you can try the following steps to troubleshoot the problem:
Make sure that you have the correct versions of TensorFlow and TensorFlow.js installed in your Colab environment. You can install or upgrade them using the following commands:
!pip install --upgrade tensorflow
!pip install --upgrade tensorflowjs
Before attempting to export to TensorFlow.js, try exporting the model to other formats such as ONNX or TensorFlow SavedModel to see if those exports are successful. This can help isolate whether the issue is specific to TensorFlow.js or a more general export problem.
If the export to other formats works, but TensorFlow.js still fails, you can try manually converting the exported model to TensorFlow.js using the tensorflowjs_converter
tool. First, export the model to the TensorFlow SavedModel format:
!yolo export model=yolov8n.pt format=saved_model
Then, use the tensorflowjs_converter
to convert the SavedModel to TensorFlow.js format:
!tensorflowjs_converter --input_format=tf_saved_model --output_format=tfjs_graph_model /path/to/saved_model /path/to/tfjs_model
If none of the above steps work, consider opening an issue on the Ultralytics YOLOv8 GitHub repository with detailed information about the error and the steps you've taken to reproduce it. The maintainers and community may be able to provide further assistance.
Remember to replace /path/to/saved_model
and /path/to/tfjs_model
with the actual paths to your exported SavedModel and the desired output directory for the TensorFlow.js model.
Thank u sir
@Smith-S-S it appears that you are encountering an issue with exporting a YOLOv8 model to TensorFlow.js (tfjs) format. The error message indicates that the export to the intermediate .pb
(Protocol Buffers) format is failing, which is a necessary step before converting the model to tfjs format.
The error '_UserObject' object has no attribute 'inputs'
suggests that there might be an issue with the TensorFlow or TensorFlow.js converter version you are using, or with the way the model is being loaded or processed during the conversion.
Here are a few steps you can take to troubleshoot and potentially resolve the issue:
Check TensorFlow and TensorFlow.js Versions: Ensure that you have the correct versions of TensorFlow and TensorFlow.js installed. Compatibility issues between different versions can cause errors during export.
Update TensorFlow.js Converter: If you are using an older version of the TensorFlow.js converter, try updating it to the latest version, as it may contain fixes for issues like the one you are experiencing.
Use a Different Export Format: As a workaround, you can try exporting the model to a different format that is supported by TensorFlow.js, such as the SavedModel format, and then use the TensorFlow.js converter to convert the SavedModel to tfjs format.
Check for Known Issues: Review the Ultralytics YOLOv8 GitHub issues to see if others have reported similar problems and if there are any suggested solutions or workarounds.
Report the Issue: If none of the above steps resolve the issue, consider reporting it on the Ultralytics YOLOv8 GitHub repository. Provide detailed information about the error, the steps you've taken, and the environment in which you are running the export command.
Use a Stable Environment: Sometimes, running the export in a different environment (e.g., a local machine with a stable setup) can help identify if the issue is specific to the Colab environment.
Manual Conversion: If the CLI command continues to fail, you can attempt to manually convert the model to tfjs format by following the TensorFlow.js conversion instructions. This may involve exporting the model to a TensorFlow SavedModel first and then using the TensorFlow.js converter.
Remember to keep your Colab environment updated and to restart the runtime if you make any changes to the installed packages. If you continue to face issues, reaching out to the Ultralytics support or community may provide additional assistance.
Search before asking
YOLOv8 Component
No response
Bug
I need to export yolov8n to tfjs json model but when I run the following CLI command in colab it throws multiple errors:
!yolo export model=yolov8n.pt format=tfjs
this is because export to pb format fails, so I tried to export to pb first but it throws "_UserObject' object has no attribute 'inputs'" error. after running the export command
yolov8n_web_model/model.json
is empty and no tfjs bin file is generated.error: