Skip to content

How to get simple inference result as txt #6382

Open
@halzhen

Description

Search before asking

Question

I am trying to inference on a batch of images in a directory. The basic inference code is the one used , I have already read the documentation for the Detections return, is there any way to get the detected objects as .txt ? In a similar way to result.print() , it shows the objects and the times they appear.

I am aware that detect.py can save as .txt but couldn't do inference on batch of images with it.

model = torch.hub.load('ultralytics/yolov5', 'yolov5s')

# Images
directory = 'keyframes/'

frames = [] # batch of images
for filename in os.listdir(directory):
    frame = Image.open('keyframes/'+filename)
    frames.append(frame)

# Inference
results = model(frames, size=640) 

# Results
results.print()
results.save()  ```

What I need is the objects detected in a .txt file without using detect.py, but if detect.py can be modified to work on batch of images from a directory that would also work. 


### Additional

_No response_

Metadata

Assignees

No one assigned

    Labels

    TODOHigh priority itemsquestionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions