Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_labels.csv #37

Open
cherryolg opened this issue Apr 18, 2022 · 16 comments
Open

test_labels.csv #37

cherryolg opened this issue Apr 18, 2022 · 16 comments

Comments

@cherryolg
Copy link

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!

@Ellyuca
Copy link

Ellyuca commented Sep 19, 2022

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.

@RamishRasool14
Copy link

@Ellyuca Can you share the script?

@Ellyuca
Copy link

Ellyuca commented Jan 14, 2023

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()

@RamishRasool14
Copy link

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?

@Ellyuca
Copy link

Ellyuca commented Jan 14, 2023

Hi @RamishRasool14.
This is the checkpoint that I have downloaded a while back:
https://file.io/77S7MMB5a631

@RamishRasool14
Copy link

RamishRasool14 commented Jan 14, 2023

Screenshot 2023-01-14 at 11 38 40 PM
Hello @Ellyuca
can you please upload again. i think it is a 1 time download link

@Ellyuca
Copy link

Ellyuca commented Jan 14, 2023

@RamishRasool14
Copy link

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!

@Ellyuca
Copy link

Ellyuca commented Jan 18, 2023

Hi @RamishRasool14 .
Glad I could help out!

@Joy-liningqiao
Copy link

@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?

@Ellyuca
Copy link

Ellyuca commented Jun 12, 2023

@Joy-liningqiao
I think this was the pretrained model.
https://file.io/xAOhkOVNUg06

@Joy-liningqiao
Copy link

Joy-liningqiao commented Jun 12, 2023 via email

@Joy-liningqiao
Copy link

Joy-liningqiao commented Jun 12, 2023 via email

@Ellyuca
Copy link

Ellyuca commented Jun 12, 2023

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.

@Joy-liningqiao
Copy link

Joy-liningqiao commented Jun 12, 2023 via email

@Ellyuca
Copy link

Ellyuca commented Jun 13, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants