-
-
Notifications
You must be signed in to change notification settings - Fork 16.7k
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
export to saved_model with --nms flag yields incorrect/incomplete results. #7205
Comments
👋 Hello @tylertroy, 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 screenshots and minimum viable code to reproduce your issue, otherwise we can not help you. If this is a custom training ❓ Question, please provide as much information as possible, including dataset images, training logs, screenshots, and a public link to online W&B logging if available. For business inquiries or professional support requests please visit https://ultralytics.com or email support@ultralytics.com. RequirementsPython>=3.7.0 with all requirements.txt installed including PyTorch>=1.7. 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 (train.py), validation (val.py), inference (detect.py) and export (export.py) on MacOS, Windows, and Ubuntu every 24 hours and on every commit. |
I have found part 2 of my issue was due to operator error whereby input was not normalized to 255. I am now getting sensible output (See rectified output image below) but part 1 whereby no classes or scores are returned still remains an issue. Edit: I will note that the ties have not been detected but it's possible that there is a difference in thresholds between detect.py and what is exported. |
I managed to solve the part 1 issue with the following edit to diff --git a/export.py b/export.py
index 7517dc4..0404b25 100644
--- a/export.py
+++ b/export.py
@@ -276,7 +276,7 @@ def export_saved_model(model, im, file, dynamic,
m = m.get_concrete_function(spec)
frozen_func = convert_variables_to_constants_v2(m)
tfm = tf.Module()
- tfm.__call__ = tf.function(lambda x: frozen_func(x)[0], [spec])
+ tfm.__call__ = tf.function(lambda x: frozen_func(x)[:4], [spec])
tfm.__call__(im)
tf.saved_model.save(
tfm, And this results in the following inputs/outputs as visualized with $ saved_model_cli show --dir yolov5s_saved_model/ --signature_def serving_default --tag serve
The given SavedModel SignatureDef contains the following input(s):
inputs['x'] tensor_info:
dtype: DT_FLOAT
shape: (1, 640, 640, 3)
name: serving_default_x:0
The given SavedModel SignatureDef contains the following output(s):
outputs['output_0'] tensor_info:
dtype: DT_FLOAT
shape: (1, 100, 4)
name: PartitionedCall:0
outputs['output_1'] tensor_info:
dtype: DT_FLOAT
shape: (1, 100)
name: PartitionedCall:1
outputs['output_2'] tensor_info:
dtype: DT_FLOAT
shape: (1, 100)
name: PartitionedCall:2
outputs['output_3'] tensor_info:
dtype: DT_INT32
shape: (1)
name: PartitionedCall:3
Method name is: tensorflow/serving/predict I'm still having an issue whereby output is different between detect.py and results from tfserve but I will raise this in a separate issue if I can't find a solution in the existing issues. I will leave closing of this issue to the authors in case they would like to incorporate the fix in |
@tylertroy hi, thank you for your feature suggestion on how to improve YOLOv5 🚀! It looks like you've uncovered a bug and implemented and tested a fix. Would you like to submit a PR to receive credit for this? Please see our ✅ Contributing Guide to get started. |
Fix for #7205 proposed by @tylertroy
* SavedModel TF Serve Fix Fix for #7205 proposed by @tylertroy * Update export.py
* SavedModel TF Serve Fix Fix for ultralytics#7205 proposed by @tylertroy * Update export.py
Search before asking
YOLOv5 Component
Export
Bug
Relates to two issues resulting from exporting exporting to saved_model with the
--nms
flag set.--nms
flag compared to 4 boxes (2 persons, 2 ties) without--nms
flagAfter exporting with the command
The output from
saved_model_cli
shows the following inputs/outputsThis indicates that the output is a tensor of 100 rows of bbox data. Visualization of these output boxes shows:
python export.py --weights yolov5s.pt --include saved_model --nms python test_serve.py # Here test_serve uses the tensroflow serve restful API
I have confirmed that the export function works perfectly well with no nms when doing inference with
detect.py
Output from model with no nms using:
Environment
Minimal Reproducible Example
No response
Additional
No response
Are you willing to submit a PR?
The text was updated successfully, but these errors were encountered: