Search code examples
pythongoogle-colaboratoryyolo

google colab execute other python file in a for loop


Currently im doing object detection with yolov7 and now i need to detect in multiple images. As you can read in the title im working in google colab, so i execute python files like this:

!python ../yolov7/detect.py --weights ../yolov7/yolov7.pt --conf 0.5 --img-size 640 --source file.jpg --save-txt 

Is the any way to loop this with a for loop, so i can detect in multiple images? Something like this dont work actually:

currentPath = os.getcwd()
files = os.listdir(currentPath)
for x in range (1):
  #print(files[x])
  currentName = "pressureGaugeImg_" + str(x)
  !python ../yolov7/detect.py --weights ../yolov7/yolov7.pt --conf 0.5 --img-size 640 --source currentName.jpg --save-txt 

He does not use the variable currentName instead of this, he searches for the file "currentName.jpg" Seems like im mixing a execution code from google colab with python, so is there any way to do this in colab?


Solution

  • For everyone who wants to know, the solution was:

    !python ../yolov7/detect.py --weights ../yolov7/yolov7.pt --conf 0.5 --img-size 800 --source pressureGauge_{x}.jpg
    

    Just put the wanted variable in {}