Open cherryolg opened 2 years ago
Hi @cherryolg. Did yo manage to figure this out? Thanks.
later edit: i just modified the testing script to read the images directly from a folder, instead of taking the images name from a csv file. hope it helps.
@Ellyuca Can you share the script?
Hi @RamishRasool14 . I think this was it. It has been some time since I last used it. Let me know if it works. Basically I just skip the step where I read the data from the .csv file and just read the images from a folder.
import argparse
import os
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image
import pandas as pd
from tqdm import tqdm
import torch
import torchvision.models as models
import torchvision.transforms as transforms
from model.model import *
parser = argparse.ArgumentParser()
parser.add_argument('--model', type=str, help='path to pretrained model')
#parser.add_argument('--test_csv', type=str, help='test csv file')
parser.add_argument('--test_images', type=str, help='path to folder containing images')
parser.add_argument('--workers', type=int, default=4, help='number of workers')
parser.add_argument('--predictions', type=str, help='output file to store predictions')
args = parser.parse_args()
base_model = models.vgg16(pretrained=True)
model = NIMA(base_model)
try:
model.load_state_dict(torch.load(args.model))
print('successfully loaded model')
except:
raise
seed = 42
torch.manual_seed(seed)
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = model.to(device)
model.eval()
test_transform = transforms.Compose([
transforms.Resize(256),
#transforms.RandomCrop(224),
transforms.CenterCrop(224),
transforms.ToTensor(),
transforms.Normalize(mean=[0.485, 0.456, 0.406],
std=[0.229, 0.224, 0.225])
])
testing_imgs = args.test_images
print("testing_imgs:", os.listdir(testing_imgs))
images_list = os.listdir(testing_imgs)
mean, std = 0.0, 0.0
for i,img in enumerate(images_list):
print("here:", i,img)
im = Image.open(os.path.join("/content/some_original_images", str(img))) #the path to the folder with images
im = im.convert('RGB')
imt = test_transform(im)
imt = imt.unsqueeze(dim=0)
imt = imt.to(device)
with torch.no_grad():
out = model(imt)
out = out.view(10, 1)
for j, e in enumerate(out, 1):
mean += j * e
for k, e in enumerate(out, 1):
std += e * (k - mean) ** 2
std = std ** 0.5
if not os.path.exists(args.predictions):
os.makedirs(args.predictions)
with open(os.path.join(args.predictions, 'my_pred.txt'), 'a') as f:
f.write(str(img) + ' mean: %.3f | std: %.3f\n' % (mean, std))
mean, std = 0.0, 0.0
#pbar.update()
Thank you very much @Ellyuca I will let you know if this works. Also do you have a pre-trained checkpoint for this, your own or if you happen to have downloaded from the provided now broken drive link?
Hi @RamishRasool14. This is the checkpoint that I have downloaded a while back: https://file.io/77S7MMB5a631
Hello @Ellyuca
can you please upload again. i think it is a 1 time download link
@RamishRasool14 try this: https://file.io/20aCY0s7alu5 or this:https://easyupload.io/djns9e
Hello @Ellyuca Wanted to let you know the code and checkpoints are working fine and thank you for sharing it with me. Just had to made minor adjustments to the code with the absolute path because you had changed it for your machine. Rest it is working perfect. Thanks again!
Hi @RamishRasool14 . Glad I could help out!
@RamishRasool14 try this: https://file.io/20aCY0s7alu5 or this:https://easyupload.io/djns9e
Hi @Ellyuca, I encountered a similar problem, could you please send me a link?
@Joy-liningqiao I think this was the pretrained model. https://file.io/xAOhkOVNUg06
Thank you so much @Ellyuca, I appreciate it!
On Jun 12, 2023, at 3:31 AM, Ellyuca @.***> wrote:
@Joy-liningqiao https://github.com/Joy-liningqiao I think this was the pretrained model. https://file.io/xAOhkOVNUg06 https://file.io/xAOhkOVNUg06 — Reply to this email directly, view it on GitHub https://github.com/yunxiaoshi/Neural-IMage-Assessment/issues/37#issuecomment-1586748122, or unsubscribe https://github.com/notifications/unsubscribe-auth/AO6Y2E3D7CEJOVUZPTQTNNTXK3AWVANCNFSM5TVGHAKA. You are receiving this because you were mentioned.
Hi @Ellyuca, could you please send it to me again? It was previously shown as available for download, but I intended to download it via laptop just now, and it has been deleted. Sorry for the inconvenience and thank you again.
On Jun 12, 2023, at 3:31 AM, Ellyuca @.***> wrote:
@Joy-liningqiao https://github.com/Joy-liningqiao I think this was the pretrained model. https://file.io/xAOhkOVNUg06 https://file.io/xAOhkOVNUg06 — Reply to this email directly, view it on GitHub https://github.com/yunxiaoshi/Neural-IMage-Assessment/issues/37#issuecomment-1586748122, or unsubscribe https://github.com/notifications/unsubscribe-auth/AO6Y2E3D7CEJOVUZPTQTNNTXK3AWVANCNFSM5TVGHAKA. You are receiving this because you were mentioned.
Hi @Joy-liningqiao. I can resend it to you tomorrow morning. I don't have access to it atm.
I'll try to put it on Google drive and leave the link available.
Sounds great! I appreciate it.
On Jun 12, 2023, at 6:07 PM, Ellyuca @.***> wrote:
Hi @Joy-liningqiao https://github.com/Joy-liningqiao. I can resend it to you tomorrow morning. I don't have access to it atm.
— Reply to this email directly, view it on GitHub https://github.com/yunxiaoshi/Neural-IMage-Assessment/issues/37#issuecomment-1588173135, or unsubscribe https://github.com/notifications/unsubscribe-auth/AO6Y2EZ6DYS7HFNBOULPUYLXK6HLTANCNFSM5TVGHAKA. You are receiving this because you were mentioned.
Hi @Joy-liningqiao,
here is the link to the model: https://drive.google.com/drive/folders/1WvWWj7_U8pcoFRQnJ-4uaoBuICbHlz3A?usp=sharing Let me know if you are able to download it, otherwise I will look for another solution.
Hello, when I want to test my image, how does test_labels.csv get generated? What does test_labels.csv mean? Looking forward to your answer!