dingkeyan93 / Intrinsic-Image-Popularity

The pytorch code of the paper "Intrinsic Image Popularity Assessment"

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Input a list of image paths

juliechoong opened this issue · comments

Is there a way to input a list of image paths instead of manually typing each path? Or is there a way it can read a text file of image paths?

Delete last "IF" command from "test.py" and paste this. Also, you will probably need to change "path" variable according to your needs.

if __name__ == '__main__':
path = "C:\\Users\\Ivan\\Desktop\\Intrinsic-Image-Popularity-master\\INPUT\\"
directories = os.listdir(path)
for file in directories:
image = Image.open(path + file)
model = torchvision.models.resnet50()
model.fc = torch.nn.Linear(in_features=2048, out_features=1)
model.load_state_dict(torch.load('model/model-resnet50.pth', map_location=device))
model.eval().to(device)
predict(image, model)

Also, add this to print to know which file it is.
print(r'Popularity score: %.2f' % preds.item() + " # " + file)

Thank you so much! It works like a charm now.