-
-
Notifications
You must be signed in to change notification settings - Fork 16.8k
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
Train YOLOv5 on Tiff (image and label format) #11840
Comments
@HelenVe hi there! Thank you for reaching out with your question. Training YOLOv5 with .tiff files should be possible. However, based on your description and the screenshot you provided, it seems that you might be encountering some issues with your data preparation or file format. To help you further, could you please provide more details? Specifically:
Having these additional details will allow me to provide you with more accurate guidance. Looking forward to assisting you! Best regards. |
@glenn-jocher Thank you very much for the quick reply! I am saving the tif files with tiffile, this is how I create them.
1 0.17875 0.5375234521575984 0.010625 0.03470919324577861 |
@HelenVe You're welcome! Thank you for providing more information. Your approach to saving the .tif files using the Regarding the label file formatting, it appears to follow the YOLOv5 format where each line represents a bounding box annotation. Each line starts with the class index (e.g., 1, 3, 5) followed by the normalized coordinates of the bounding box (x_center, y_center, width, height). From what you've described and the example you provided, there doesn't seem to be any issues with the file formats or labeling. However, there might be other factors affecting your training performance. To investigate this further, here are a few suggestions:
Please give these suggestions a try and let me know if you observe any improvements in your training results. If you have any further questions or concerns, don't hesitate to ask. Happy training! |
@glenn-jocher Hello, I have the same issues. I have trained my model with .tiff images, but the results are extremely poor. After running detect.py, the predicted results have no prediction frame, unless adjusting the conf-threshold to 0. I know there must be something wrong with my project, but I cannot find it. Help me, please! |
@RanwanWu hi, Thank you for reaching out and bringing this issue to our attention. I understand that you have trained your YOLOv5 model using .tiff images, but the results are not satisfactory. To address this, let's try to troubleshoot the problem together. Here are a few suggestions to get you started:
Please try these suggestions and let us know if you observe any improvements in your results. If the issue persists, provide us with more specific information about your project setup and any error messages you encounter, so that we can further assist you. Keep in mind that the YOLOv5 model is a product of the collective efforts of the YOLO community and the Ultralytics team. We are here to support you in troubleshooting and finding a solution. Thank you for your patience, and we'll do our best to help you resolve this issue. Glenn Jocher |
@RanwanWu for me, the training and validation results are now very good, I adjusted the channel number in yolo.py file for my case, and also in the dataloader.py I changed the cv2.imread() in the load_image() function into tiffile.imread() so that the correct number of channels is read. cv2.imread() always converts the images to 3 channel images so if you have grayscale tiffs it's going to convert them. However when running detection I also get poor results, but maybe that's the model not performing well. Hope this relates to your issue. |
@HelenVe, I'm glad to hear that you were able to improve the training and validation results by making adjustments to the code. The modifications you mentioned in Regarding poor results during detection, it's possible that the model's performance might be a factor. Keep in mind that YOLOv5's performance can vary depending on several factors, such as the dataset, training configuration, and model architecture. It's recommended to experiment with different training configurations, hyperparameters, and model architectures to potentially improve the detection results. Additionally, evaluating the model's performance using appropriate metrics like precision, recall, and mAP can help provide a better understanding of its capabilities. If you have any further questions or need assistance with any specific aspect, please let us know. We're here to help you. Glenn Jocher |
@glenn-jocher You're right, could you maybe give me some insight on the training results? I trained a YOLOv5m model from scratch, by stacking 10 heatmaps produced by the GradCAM++ explainability algorithm. I also did the same for HiresCAM (which has more precise heatmaps). These are my training results for the GradCAM base. I didn't use any data augmentation. |
@HelenVe training YOLOv5 models from scratch with stacked heatmaps from the GradCAM++ algorithm is an interesting approach. However, it's important to note that the training results you shared indicate that the model is currently not performing well. To further investigate and improve the training results, I would recommend considering the following points:
By addressing these points, you may be able to enhance the training results of your YOLOv5m model. Remember to evaluate the model's performance using appropriate metrics like mAP (mean Average Precision) and precision/recall to assess its detection capabilities accurately. If you have any further questions or need additional guidance, please don't hesitate to ask. We're here to help you. Glenn Jocher |
Thank you for the reply. I am using only one class to train the model which I specify in the include_class array in dataloaders.py, but in the yaml files I have more classes defined. Also I was wondering how can you tell from the plots that the model isn't performing well? |
@HelenVe thank you for your question. Regarding using only one class to train the model, if you have specified the desired class in the As for the performance evaluation, the plots you provided do not directly indicate whether the model is performing well or not. More detailed evaluation is typically required to assess the model's performance accurately. This can include calculating metrics like mAP (mean Average Precision), precision, recall, and/or using an evaluation tool such as CocoEval. To better understand the model's performance, you might want to consider evaluating it on a separate validation or test dataset. This evaluation can help assess the model's ability to accurately detect and classify objects. If you have any further questions or need additional guidance, please feel free to ask. We're here to assist 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 ⭐ |
Hello @HelenVe , I am also trying to train yolov5 with more than 3 band images. Thank you for your time. |
Hello @mpapadomanolaki, Great to hear that your training and validation results have improved! Regarding the issue with detection, it might be beneficial to review the detection settings such as the confidence threshold and non-max suppression threshold to ensure they are optimally configured for your specific use case. For the error about corrupt TIFF images, it sounds like there might be an issue with how the images are being read or processed. Ensure that import tifffile
image = tifffile.imread('path_to_your_image.tif')
print(image.shape) If this prints the expected dimensions without errors, your images are likely fine, and the issue might be elsewhere in the data handling or preprocessing steps. If you continue to face issues, please provide more details about the error messages you're seeing, and we can troubleshoot further! |
hi, i also want to ask you about possibility of retrieving the bounding boxes coordinates from detected tiff image using yolov5, is that possible that i detect tiff image with yolov5 and getting the bounding boxes coordinate so that i can display the geospatial reference data in software such as ArcGIS and QGIS? |
Hello @hafidhhusna, Thank you for your question! Yes, it is indeed possible to retrieve the bounding box coordinates from detected TIFF images using YOLOv5. Here's a step-by-step guide to help you achieve this:
By following these steps, you should be able to retrieve the bounding box coordinates from detected TIFF images and use them in geospatial software like ArcGIS and QGIS. If you encounter any issues or have further questions, please provide a minimum reproducible code example so we can better assist you. You can refer to our minimum reproducible example guide for more details. Also, make sure you are using the latest versions of Happy coding! 😊 |
thank you for your quick response! i also want to ask you if i'm gonna perform inference with tiff file as input, do i have to train the model with the tiff file as well? if so, can you give me the guide for that? |
Hello @hafidhhusna, Thank you for your question! 😊 To answer your query: Yes, if you plan to perform inference with TIFF files as input, it is generally a good practice to train the model with TIFF files as well. This ensures that the model learns the specific characteristics and nuances of your TIFF images, leading to better performance during inference. Here's a step-by-step guide to help you train YOLOv5 with TIFF files:
Here's a brief example of how you might modify the data loading part: import tifffile
def load_image(path):
# Load TIFF image
img = tifffile.imread(path)
return img
# Load the YOLOv5 model
model = torch.hub.load('ultralytics/yolov5', 'custom', path='path_to_your_model.pt')
# Load the TIFF image
image = tifffile.imread('path_to_your_image.tif')
# Perform inference
results = model(image)
# Print results
results.print() If you encounter any issues or have further questions, please provide a minimum reproducible code example so we can better assist you. You can refer to our minimum reproducible example guide for more details. Also, make sure you are using the latest versions of I hope this helps! If you have any more questions, feel free to ask. Happy coding! 🚀 |
Thank you for the response @glenn-jocher ! |
Hello @hafidhhusna, Thank you for reaching out! 😊 To use your GeoJSON annotations with YOLOv5, you'll need to convert them into the YOLO format, which consists of text files where each line represents a bounding box in the format: Here's a step-by-step guide to help you convert your GeoJSON annotations to YOLO format:
Here's a sample script to help you get started: import json
import os
def convert_geojson_to_yolo(geojson_path, output_dir, image_width, image_height):
with open(geojson_path, 'r') as f:
geojson_data = json.load(f)
for feature in geojson_data['features']:
# Extract class label and bounding box coordinates
class_label = feature['properties']['class']
bbox = feature['geometry']['coordinates'][0]
# Convert to YOLO format
x_min, y_min = bbox[0]
x_max, y_max = bbox[2]
x_center = (x_min + x_max) / 2 / image_width
y_center = (y_min + y_max) / 2 / image_height
width = (x_max - x_min) / image_width
height = (y_max - y_min) / image_height
# Save to YOLO format
yolo_label = f"{class_label} {x_center} {y_center} {width} {height}\n"
output_file = os.path.join(output_dir, f"{feature['properties']['image_id']}.txt")
with open(output_file, 'a') as f_out:
f_out.write(yolo_label)
# Example usage
convert_geojson_to_yolo('path_to_your_geojson.geojson', 'path_to_output_labels', image_width=1024, image_height=1024) Alternative Labeling Tools: Next Steps:
If you encounter any issues or need further assistance, please provide a minimum reproducible code example so we can better assist you. You can refer to our minimum reproducible example guide for more details. Also, ensure you are using the latest versions of I hope this helps! If you have any more questions, feel free to ask. Happy coding! 🚀 |
But those labelling tools such as labelimg and roboflow doesnt support tiff file isn't it? I have tried once using roboflow to label my tiff file, but roboflow just doesnt support tiff file as input |
Hello @hafidhhusna, Thank you for your insightful question! 😊 You are correct that some popular labeling tools like LabelImg and Roboflow may not natively support TIFF files. However, there are a few workarounds and alternative approaches you can consider:
If you decide to convert your TIFF files to PNG or JPEG for annotation, remember to maintain the same aspect ratio and dimensions to ensure the annotations remain accurate when you convert them back. If you encounter any issues during this process or have further questions, please provide a minimum reproducible code example so we can better assist you. You can refer to our minimum reproducible example guide for more details. Also, ensure you are using the latest versions of I hope this helps! If you have any more questions, feel free to ask. Happy coding! 🚀 |
If the tiff file converted to png, does it keeps the geospatial references? |
Hello @hafidhhusna, Thank you for your question! 😊 When converting a TIFF file to PNG, the geospatial references (metadata) are typically not preserved in the PNG file. TIFF files can store extensive metadata, including geospatial information, which is crucial for applications like GIS. However, PNG files do not support this kind of metadata natively. If maintaining geospatial references is essential for your workflow, you have a couple of options:
If you encounter any issues or need further assistance, please provide a minimum reproducible code example so we can better assist you. You can refer to our minimum reproducible example guide for more details. Also, ensure you are using the latest versions of I hope this helps! If you have any more questions, feel free to ask. Happy coding! 🚀 |
My TIFF files are too large and exceed the reading threshold of Pillow. Is there a way to handle this issue without manually resizing or annotating the images? |
To handle large TIFF files in YOLOv5 without manual resizing, you can use import tifffile
def load_image(path):
return tifffile.imread(path, mode='mmap') # memory-mapped for large files For geospatial TIFFs, consider using If issues persist, please share a minimal reproducible example. |
I'm a novice, and I support TIFF files in the LabelImg I use, so which line should these codes be added to? |
To add TIFF support in LabelImg, you'll need to modify the image loading function in LabelImg's source code. Replace OpenCV's |
Search before asking
Question
Hello!
I have a question regarding training of YOLOv5 with .tiff files.
I have 10 grayscale images, each of them corresponds to a class. I stack and save them on a tif file, the shape per tif is [10, image_width, image_height]. Some of these grayscale images can also be empty. I have a label file per tif, containing all the class bounding boxes.
However when I start training, my metrics values are very low (see screenshot) so I must be doing something wrong. Is my logic incorrect, should I be saving the images in a different way?
Thank you for your time!
Additional
No response
The text was updated successfully, but these errors were encountered: