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

Added requirements.txt and CPU only inference option #10

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
env/
12 changes: 12 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
clip==0.2.0
datasets==2.10.1
matplotlib==3.7.1
numpy==1.24.2
openai_clip==1.0.1
pandas==1.5.3
Pillow==9.4.0
pytorch_lightning==2.0.0
torch==2.0.0
torchvision==0.15.1
tqdm==4.65.0
webdataset==0.2.48
21 changes: 9 additions & 12 deletions simple_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@

img_path = "test.jpg"





# if you changed the MLP architecture during training, change it also here:
class MLP(pl.LightningModule):
def __init__(self, input_size, xcol='emb', ycol='avg_rating'):
Expand Down Expand Up @@ -91,15 +87,16 @@ def normalized(a, axis=-1, order=2):

model = MLP(768) # CLIP embedding dim is 768 for CLIP ViT L 14

s = torch.load("sac+logos+ava1-l14-linearMSE.pth") # load the model you trained previously or the model available in this repo
device = "cuda" if torch.cuda.is_available() else "cpu"

# load the model you trained previously or the model available in this repo
s = torch.load("sac+logos+ava1-l14-linearMSE.pth", map_location=device)

model.load_state_dict(s)

model.to("cuda")
model.to(device)
model.eval()


device = "cuda" if torch.cuda.is_available() else "cpu"
model2, preprocess = clip.load("ViT-L/14", device=device) #RN50x64


Expand All @@ -114,9 +111,9 @@ def normalized(a, axis=-1, order=2):

im_emb_arr = normalized(image_features.cpu().detach().numpy() )

prediction = model(torch.from_numpy(im_emb_arr).to(device).type(torch.cuda.FloatTensor))

if device == "cuda":
prediction = model(torch.from_numpy(im_emb_arr).to(device).type(torch.cuda.FloatTensor))
else:
prediction = model(torch.from_numpy(im_emb_arr).to(device).type(torch.FloatTensor))
print( "Aesthetic score predicted by the model:")
print( prediction )


Binary file added test.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.