-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
How do I save the images of the yolov8 training predictions? #375
Comments
you can use results = model("path to your image" , save=True) |
|
|
@kyoko9000 where does it save? And does it also work for stream=True |
@kyoko9000 it will save on runs\detect\predict folder |
found it .. it was confusing that the runs folder is saved two directories back |
if you don't need further clarification please close the issue |
is |
The 'save' option needs to be listed under 'Configuration'. |
Add save = True at end. That is, |
How do define the location where it will save? |
@RelativelyFine By default it'll save to |
try using this code it is working for me,it was really good but I want here cropping of detected bounding box and save it into disk, if anyone can help me please from ultralytics import YOLO model = YOLO("model/best.pt") |
To save crops you can use save_crop=True |
Thanks it worked |
Ultralytics now use the flag "save=True" to save results. to save the output results by making runs folder |
Here you can send an image through the Yolov8 model and get predictions. from ultralytics import YOLO model = YOLO("best.pt") results = model.predict(source=path, show=True, save=False, save_txt=False, save_conf=False) |
is there any way for live web cam usage? |
accepts all formats - image/dir/Path/URL/video/PIL/ndarray. 0 for webcam |
Let's say I want to run my model over a large dataset, can I also make it so only detections above, say 0.6 confidence are saved? |
@Camerabiologist you can set conf to any value you'd like during predict:
|
@Camerabiologist you can set conf to any value you'd like during predict:
|
Thanks @glenn-jocher! My current yolo predict outputs my full dataset including detections and non-detections. I want to filter out the non-detections from the resulting Predict_xx folder. |
@Camerabiologist see https://docs.ultralytics.com/modes/predict for examples |
@Laughing-q > @RelativelyFine By default it'll save to Could you please give a short example code of customizing predicting save path? |
model = YOLO("yolov8n.pt")
model.predict(source=..., project="xx", name="xxx") then it'll be save in |
Great! It worked, thanks! |
@glenn-jocher Aha your advice worked, below is the script I am using to isolate segmented masks, place white mask over segmented object, black out areas not segmented. You my good sir have acquired a new sponsor. Now, I am need to work on optimizing the scripts and/or dataset (current is 92 jpg's at 1 mb each & txt's are around 50 kb) so training time reduces from x2 (7:50 min per epoch) to 3 min per epoch, this time was prior to implementing the Isolate segmented object script. Isolate Segmented Objects & Save as Masks
Masks to Polygons
Train pre-trained weight
|
@dronespov Hi Andrew, I'm thrilled to hear the advice helped! Your scripts look well-organized and appear to serve their intended purposes effectively. Thank you for the support, it's truly appreciated! To optimize training time:
Reducing training time often involves a mix of tweaks to model configurations and efficient resource management. Focus on the most impactful changes to see significant reductions in epoch duration. Keep up the fantastic work!
|
@glenn-jocher Turns out I included an additional directory by accident and that caused training time to x2-3. When I removed the directory, training time reduced. Im trying to make my training and retraining process more efficient. Do you know if there's a way to Predict & segment objects in one script then in a second script import the segmented results, isolate the segmented objects, white mask the object, and black out the undetected areas? Currently the below script Predicts, Segments, Isolates, White & Black Masks in one script. Id like to separate that process into two scripts.
|
@dronespov Hi Andrew, Glad to hear you resolved the training time issue by adjusting the directory setup. To streamline your workflow into two separate scripts:
This separation allows you to handle the prediction and post-processing steps independently, potentially enabling more efficient use of computational resources. Remember, for the first script, focus on generating and storing all the necessary data for further processing in a structured manner. The second script will then access this stored data to complete the masking and isolation tasks. Keep refining your process!
|
Hi @glenn-jocher Everything is running well, thanks for all your help. I am now trying deploy the weight to sagemaker so when I upload an image to my website, it passes through s3,then lambda, then sagemaker, and predicted results back to s3. Do you know of any informative articles or videos that you'd recommend for building this flow? |
@dronespov hi Andrew, I'm delighted to hear your project is progressing smoothly. For deploying a model on AWS SageMaker with the workflow you've described, I would suggest exploring the official AWS documentation and tutorials on SageMaker, Lambda, and S3 services. AWS also provides sample notebooks and code repositories that illustrate similar end-to-end processes. Best of luck with your deployment!
|
@glenn-jocher Do you have any documentation for adding a new class to a pre-trained model? Im trying to add a new class by specifying it in the annotation and config set but when I check the val mosaic, the images are being classified as cat(0) for example im trying to add dog as the second class. In the labeling process I define dog as 1 then add the images and labels to the new training dataset. When I evaluate the val mosaic, dogs (1) are registering as cats (0) config.yaml path: 'path/to/dataset' # dataset root dir Classesnames: |
@dronespov hi there, To add a new class to a pre-trained model, you'll need to update your dataset's annotation files to include the new class index and label, and then modify the If the new class is being misclassified, it's important to double-check that the annotations are correct and that the Retraining from scratch or fine-tuning the pre-trained model with the updated dataset should then recognize and classify the new class correctly.
|
@glenn-jocher Is there any way to add a new class to a pre trained model without a retraining the entire model? Im thinking if it's possible to add a new class with associated dataset then continue retraining previous model to detect the new class.
|
@dronespov Hi Andrew, Yes, you can add a new class to a pre-trained model without starting from scratch. You'll need to update your dataset and
|
@glenn-jocher Understood, I've tried that approach but unsuccessful. For some reason, my new class id is being identified as a different class id. I did some research and found the annotation tool I use - CVAT - sets label id as default 1-9. I tried changing the ID # for the new class in their website but their website reverts the changed id # to the default id # ( e.g dog id 1 changed to 0 then their website reverts it back to 1). I submitted that as a bug to their team, hopefully will get that fixed soon.
|
@dronespov Hi Andrew, It seems like the issue is with the annotation tool's class ID assignment. Good job on reporting the bug to the CVAT team. In the meantime, you might consider manually adjusting the class IDs in your annotation files to match your
|
@glenn-jocher Manually changing the class-index helped, thanks for the tip. Do you know if there's a way to From CVAT, export the Segmented Masks and Convert the Segmentation Class to txt with the correct class index?
|
@dronespov Hi Andrew, Glad to hear that manually adjusting the class index was helpful. Regarding your question, CVAT does allow you to export annotations in different formats, including masks. However, converting these masks to YOLO format Your script approach for converting masks to
|
@glenn-jocher when train my pretrained model on a new class, the resulted weight only detects the new class, and excludes the previously trained class. Do you have any idea why this is occurring?
|
@dronespov Hi Andrew, This typically happens if the new training dataset only contains the new class. Ensure your dataset includes examples of both the new and previously trained classes. Also, verify that the
|
Hi, Does anyone know how to save the segmentation prediction without the bounding box? |
Define boxes parameter as True or False in predict. example
|
I figured out how to add a new class to my pretrained model. The complication I'm facing now is when I train the new class, my old class is showing poor prediction results. For example; The new class is dog. My previous class (cat) has months of trained progress & is predicting cats well. My classes are 0: Cat When I train dog with 30 images & 300 epochs, dog prediction performs well. Although, cat performance on the new weight only registers 1 cat in a photo with 20 cats compared to 15 cats in a photo with 20 cats. Conf = 0.1 on both prediction tests Do you know why the cat prediction performance drop is occurring? |
Hi @dronespov 👋, It sounds like you're experiencing a common issue known as "catastrophic forgetting" during incremental learning. When you train on a new class with a pre-trained model, without including the original classes in the training set, the model may forget the previous knowledge. To mitigate this, you should continue training with a dataset that includes both the new class (dog) and the previously trained class (cat). This way, the model maintains its ability to predict both classes effectively. Here's a quick example of how your training command might look: yolo train data=combined_dataset.yaml model=pretrained_weights.pt epochs=300 Make sure Happy training! 🚀 |
Hi @glenn-jocher ive tried training the new class with 30 images of Dog and 5 images of cats to ensure cats is maintained but still forgetting occurs. Should I train with more cat images? Is there documentation you could send on training new classes on pre-trained models?
|
@dronespov hi Andrew 👋, Yes, increasing the number of cat images can help. It's important to have a balanced dataset for both classes to prevent forgetting. For training on new classes with pre-trained models, ensure that your dataset is representative of all classes you want the model to recognize. While we don't have specific documentation on incremental learning, the general training guidelines apply. You might want to try techniques like mixed precision training or adjusting learning rates to fine-tune your model further. Keep experimenting with the balance, and good luck! 🐾🐱
|
@glenn-jocher lets say I have 20 classes and only want to fine tune 1 class out of the 20. How do I fine tune 1 class out of 20 while the other 19 keeping the same progress? Its a big issue that the other classes are catastrophically forgetting. |
@dronespov hi there! 👋 Fine-tuning a single class out of many without affecting the others is indeed tricky due to catastrophic forgetting. One approach is to include a modest amount of data for the 19 classes you want to preserve, alongside a larger portion for the 1 class you're focusing on. This way, the model refreshes its memory on the 19 classes while learning more about the new class. Here's a quick snippet on how you might adjust your training setup: # Consider having a balanced dataset
data='dataset.yaml' # Make sure this includes all 20 classes
# Adjust your training command
yolo train data=data.yaml model=pretrained.pt Ensure your |
@glenn-jocher could you suggest other ways to counteract catastrophic forgetting? Maybe dividing classes into multiple weights?
|
@dronespov hi Andrew K. 👋, Indeed, catastrophic forgetting is a challenge in continuous or incremental learning. Dividing classes into multiple weights, or "modular training," is a possibility. This involves training separate models for different groups of classes and combining their predictions at inference time. Another method is to employ "experience replay" where you periodically retrain the model on a subset of the old data along with the new data. This helps the model retain knowledge of previous classes. Using Elastic Weight Consolidation (EWC) is another advanced technique that protects important weights of a model from significant changes during new training sessions. Here's a quick snippet for experience replay: # Mix old data with new class data for training sessions
dataset = mix_dataset(old_data, new_data) Keep experimenting to find the best strategy for your specific use case. Happy training! 🚀
|
@glenn-jocher Regarding adding new class and model catastrophically forgetting past training progress, I've. included nearly 50 images & videos of past trained data. Still, Catastrophically forgetting is occurring. It seems as if the model is now creating a new model instead of retraining. How do you suggest I solve this catastrophic forgetting bug?
|
@dronespov hi Andrew K. 👋, It sounds like you're facing a common challenge with catastrophic forgetting. A good approach is to ensure a balanced dataset with both old and new classes during the retraining phase. Also, consider using a lower learning rate to fine-tune the model gently without overriding previous knowledge. Here's an example snippet: yolo train data=your_dataset.yaml model=pretrained_weights.pt epochs=300 lr0=0.001 # Adjust learning rate as needed Remember, consistency and a bit of trial and error go a long way! Keep experimenting, and you'll get there. 🚀
|
@glenn-jocher thank you I'll try this approach. I'm curious, why hasn't ultralytics team solved catastrophic forgetting and provided a solution in either the model or documentation? |
Hi @dronespov 👋, Great question! Catastrophic forgetting is a complex issue inherent to neural networks, especially as they learn sequentially. We're continuously exploring ways to improve this, but a one-size-fits-all solution is challenging due to varied use cases and dataset specifics. We appreciate community input like yours as it guides prioritization and development. Keep sharing your feedback and experiences! Happy experimenting! 🚀
|
Search before asking
Question
In the yolov8 interface , when I use the method predict which in the class YOLO , I do not know how to save the output images.And there maybe have not args in the method predict to save the output images.
Additional
No response
The text was updated successfully, but these errors were encountered: