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

add new aesthetic scoring model #1

Merged
merged 4 commits into from
Feb 8, 2024
Merged
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
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,18 @@ RUN (git clone https://github.com/aiXander/CLIP_assisted_data_labeling && \
cd CLIP_assisted_data_labeling && \
git checkout 09468d9)

RUN (git clone https://github.com/edenartlab/creator-lora.git && \
cd creator-lora && \
git checkout b773492e5fd4845b29ec8e8f12b7cdae71d7bec5)

COPY main.py main.py

# RUN gdown 1Pm2apRxk9CbMspwve3Fir3WwX-vDWXoL
RUN gdown 1iEcUy-fAe2h_3E7gMI4pu8tsZ187n4aC

# aesthetic_score_best_model.pth
RUN gdown 1thEIlXVc8lkULVUBY9Ab45tsOERxkjxn

EXPOSE 80

CMD ["python", "-u", "main.py"]
13 changes: 12 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import sys
sys.path.append('CLIP_assisted_data_labeling')
sys.path.append('creator-lora')

import time
import os
Expand All @@ -15,6 +16,7 @@
import chromadb
from chromadb.config import Settings
from utils.embedder import AestheticRegressor
from creator_lora.models.resnet50 import ResNet50MLP

MONGO_URI = os.getenv('MONGO_URI')
MONGO_DB_NAME = os.getenv('MONGO_DB_NAME')
Expand All @@ -23,6 +25,7 @@

# model_path = "combo_2023-08-02_03:48:00_8.1k_imgs_80_epochs_-1.0000_mse.pth"
model_path = "eden_scorer_2023-12-13_9.4k_imgs_80_epochs_2_crops.pth"
model_path_resnet50_mlp = "aesthetic_score_best_model.pth"
device = "cpu"

# setup mongo
Expand Down Expand Up @@ -53,8 +56,12 @@

# load scorer + embedder
aesthetic_regressor = AestheticRegressor(model_path, device)
aesthetic_regressor_resnet50 = ResNet50MLP(
model_path=model_path_resnet50_mlp,
device = device
)
print(aesthetic_regressor)

print(aesthetic_regressor_resnet50)

def induct_creation(document):
uri = document['thumbnail']
Expand All @@ -72,7 +79,11 @@ def induct_creation(document):

# aesthetic score
score, features = aesthetic_regressor.predict_score(image)
score_resnet50 = aesthetic_regressor_resnet50.predict_score(image)
embedding = features.squeeze().numpy().tolist()

## take mean score
score = (score + score_resnet50) / 2

if not embedding:
print(f"skip creation {document['_id']}, no embedding")
Expand Down
Loading