Coder Social home page Coder Social logo

Comments (16)

Ellyuca avatar Ellyuca commented on June 19, 2024

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.

from neural-image-assessment.

RamishRasool14 avatar RamishRasool14 commented on June 19, 2024

@Ellyuca Can you share the script?

from neural-image-assessment.

Ellyuca avatar Ellyuca commented on June 19, 2024

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

from neural-image-assessment.

RamishRasool14 avatar RamishRasool14 commented on June 19, 2024

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?

from neural-image-assessment.

Ellyuca avatar Ellyuca commented on June 19, 2024

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

from neural-image-assessment.

RamishRasool14 avatar RamishRasool14 commented on June 19, 2024

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

from neural-image-assessment.

Ellyuca avatar Ellyuca commented on June 19, 2024

@RamishRasool14 try this: https://file.io/20aCY0s7alu5 or this:https://easyupload.io/djns9e

from neural-image-assessment.

RamishRasool14 avatar RamishRasool14 commented on June 19, 2024

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!

from neural-image-assessment.

Ellyuca avatar Ellyuca commented on June 19, 2024

Hi @RamishRasool14 .
Glad I could help out!

from neural-image-assessment.

Joy-liningqiao avatar Joy-liningqiao commented on June 19, 2024

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

from neural-image-assessment.

Ellyuca avatar Ellyuca commented on June 19, 2024

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

from neural-image-assessment.

Joy-liningqiao avatar Joy-liningqiao commented on June 19, 2024

from neural-image-assessment.

Joy-liningqiao avatar Joy-liningqiao commented on June 19, 2024

from neural-image-assessment.

Ellyuca avatar Ellyuca commented on June 19, 2024

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.

from neural-image-assessment.

Joy-liningqiao avatar Joy-liningqiao commented on June 19, 2024

from neural-image-assessment.

Ellyuca avatar Ellyuca commented on June 19, 2024

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.

from neural-image-assessment.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.