Closed laszlovandenhoek closed 1 year ago
Hi @laszlovandenhoek , thanks for your feedback
To add some context, the reason why both have different name is because they refer to something slightly different.
output_folder
is the folder where all the images will be saved under <output_folder>/f"pred_{i}.jpg"
. This is used for multiple images ImagesDetectionPrediction
output_path
refers to the path where the video will be saved. This includes the name of the video and the extension. This is used for video VideoDetectionPrediction
and single image prediction ImageDetectionPrediction
The motivation is that when saving a single object (video or image), we can let the user set the name (with output_path
) while when working with a set of images, each image needs to have a different name, and therefore we chose to let the use chose the folder only (with output_folder
).
Eventually, we do want to improve the logic of multiple images, because currently, the user has no control over the name of each image (i.e. f"pred_{i}.jpg
).
Concerning your solution, I am not sure if taking out the possibility of the user to choose the output video/single image name is a good thing. That being said, I totally agree that homogenizing the API would be great.
Maybe the right approach would be something similar to this:
ImagesDetectionPrediction
) as isoutput_folder
to video (VideoDetectionPrediction
) and single image (ImageDetectionPrediction
) .save
method.output_path
from both classes (Non-relevant if we already have output_folder
)output_name
to both classes as optional, to let the user chose a name. By default, output_folder="predicted_video.mp4"
or output_folder="predicted_image.jpeg"
depending on the classImagesDetectionPrediction(...).save(output_folder: str, ...)
ImageDetectionPrediction(...).save(output_folder: str, output_name: str = "predicted_image.jpeg", ...)
VideoDetectionPrediction(...).save(output_folder: str, output_name: str = "predicted_video.mp4", ...)
What do you think?
Fair enough. While we're changing method signatures, I think it would make sense to use this opportunity to also add the possibility to customize the image name in the case of ImagesDetectionPrediction
. I'm no Python wizard, but perhaps something like this could work:
from typing import Callable
...
ImagesDetectionPrediction(...).save(output_folder: str, file_naming_strategy: Callable[[int], str] = lambda i: f"pred_{i}.jpg", ...)
That would maintain backwards compatibility while providing customizability going forward.
Update; If you want to save each image with a clear and custom name, the recommended way is to simply iterate over the predictions, and save each with whatever name you want
predictions = model.predict(IMAGES)
for i, prediction in enumerate(predictions):
name = ... # Define the name the way you want. e.g. `name = f"my_custom_name_{i}"`
prediction.save(output_path=name)
(As opposed to the quick way)
predictions = model.predict(IMAGES)
predictions.show()
predictions.save(output_folder="") # Save in working directory
🚀 Feature Request
If I run
predict()
on an image, as per the YOLO-NAS quickstart, it yields anImagesDetectionPrediction
, which has asave()
method that takes anoutput_folder
argument:https://github.com/Deci-AI/super-gradients/blob/a59449726e1d55f68c96b7be24f8a00a126b59e0/src/super_gradients/training/models/prediction_results.py#L182-L184
However, if I run that same
predict()
method on a video, it yields aVideoDetectionPrediction
, whosesave()
method takes anoutput_path
argument:https://github.com/Deci-AI/super-gradients/blob/a59449726e1d55f68c96b7be24f8a00a126b59e0/src/super_gradients/training/models/prediction_results.py#L237
Considering that they mean the same thing, it was confusing to me that the method arguments are named differently, especially since it's a required parameter without a default value.
Proposed Solution (Optional)
save()
method toVideoDetectionPrediction
that takes anoutput_folder
argumentoutput_path
argument.save(output_path="")
(by analogy of the quickstart doc) currently saves the output to a file literally named.mp4
.The reason I would suggest replacing the
save()
method onVideoDetectionPrediction
instead of the one onImagesDetectionPrediction
is that the quickstart documentation is based on an image and therefore uses theoutput_path
form.