0

I trained a custom YOLOv7 model to detect a few bird species and now I want to process thousands of images to detect the species, but for my output I need to have the timestamp (so date and time) for every image in which my model recognizes a species. It would be ideal if I could add a few lines in the detect.py script to get it automatically saved in the text files created. Does anyone know if this is possible, and if yes, where and how to include this?

I found there are multiple ways to get the metadata (that includes time and date) from images in python, but I don't know how to possibly add this in the detect.py file.

Anouk
  • 1

1 Answers1

0

Looking at detect.py it seems that the image path where the output is saved is:

save_path = str(save_dir / p.name)

If you want to add timestamp info to that, you could create a folder for each run. So you could change the save_dir to include one extra folder named based on the timestamp:

save_dir /= dt.datetime.now().strftime("%Y-%m-%d-%H-%M-%S")  # or any format you want

Also make sure the folder is created!

Matteo Zanoni
  • 3,429
  • 9
  • 27
  • Thank you for your comment. Maybe my question wasn't completely clear, but what I would like to get is an extra column in the txt file with the timestamp of the image (so when the original image was taken). Or alternatively, the image name as an extra column, so that I can later match the image name with the metadata. – Anouk May 24 '23 at 17:17
  • Maybe in this part of the script? # Write results for *xyxy, conf, cls in reversed(det): if save_txt: # Write to file xywh = (xyxy2xywh(torch.tensor(xyxy).view(1, 4)) / gn).view(-1).tolist() # normalized xywh line = (cls, *xywh, conf) if opt.save_conf else (cls, *xywh) # label format with open(txt_path + '.txt', 'a') as f: f.write(('%g ' * len(line)).rstrip() % line + '\n') – Anouk May 24 '23 at 17:18