Skip to content

Commit

Permalink
Reenabled cuda support
Browse files Browse the repository at this point in the history
  • Loading branch information
ThePromidius committed Feb 27, 2024
1 parent 2316246 commit e5dd1ab
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
10 changes: 6 additions & 4 deletions MangaManager/MangaManagerCuda.spec
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# from update_version import update_version_file
# update_version_file()
from MangaManager.src.__version__ import __version__ as version_
from platform import system
from datetime import date
Expand All @@ -13,7 +15,9 @@ release_name = "_".join(
str(datetime.now().minute).zfill(2),
str(datetime.now().second).zfill(2),
system(), build_version, "_Cuda"])
# from PyInstaller.utils.hooks import collect_all

# datas = collect_all('open_clip')
a = Analysis(
['main.py'],
pathex=[],
Expand All @@ -23,10 +27,8 @@ a = Analysis(
('ExternalSources', 'ExternalSources'),
('Extensions', 'Extensions'),
# THe following are picked from env variable. Please run python to include possible missing files
('../venv_3.11/Lib/site-packages/sv_ttk/*','sv_ttk'), # To save the sv_ttk.tcl file - MISSING IMPORT
('../venv_3.11/Lib/site-packages/sv_ttk/theme*','sv_ttk/theme'), # To save the sv_ttk.tcl file - MISSING IMPORT
('../venv_3.11/Lib/site-packages/open_clip/model_configs/ViT-B-16-plus-240.json','open_clip/model_configs'), # To save the sv_ttk.tcl file - MISSING IMPORT
('../venv_3.11/Lib/site-packages/open_clip/bpe_simple_vocab_16e6.txt.gz','open_clip') # To save the sv_ttk.tcl file - MISSING IMPORT
('../.venv/Lib/site-packages/open_clip/model_configs/ViT-B-16-plus-240.json','open_clip/model_configs'), # To save the sv_ttk.tcl file - MISSING IMPORT
('../.venv/Lib/site-packages/open_clip/bpe_simple_vocab_16e6.txt.gz','open_clip') # To save the sv_ttk.tcl file - MISSING IMPORT

],
hiddenimports=['PIL._tkinter_finder','tkinterdnd2.TkinterDnD','slugify'],
Expand Down
15 changes: 8 additions & 7 deletions MangaManager/MangaManagerNoCuda.spec
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# from update_version import update_version_file
# update_version_file()
import os
import pathlib
import platform
Expand All @@ -12,6 +14,7 @@ if platform.system() == "Windows":
venv_path = VENV + "/Lib"
else:
venv_path = VENV + "/lib/python3.11"

release_name = "_".join(
["MangaManager",
str(build_date.year),
Expand All @@ -21,8 +24,9 @@ release_name = "_".join(
str(datetime.now().minute).zfill(2),
str(datetime.now().second).zfill(2),
system(), build_version, "_NoCuda"])
open_clip_libs = [(venv_path + '/site-packages/open_clip/model_configs/ViT-B-16-plus-240.json','open_clip/model_configs'), # To save the sv_ttk.tcl file - MISSING IMPORT
(venv_path + '/site-packages/open_clip/bpe_simple_vocab_16e6.txt.gz','open_clip')] if pathlib.Path(venv_path,"site-packages","open_clip").exists() else [] # To save the sv_ttk.tcl file - MISSING IMPORT],
open_clip_libs = []
# (venv_path + '/site-packages/open_clip/model_configs/ViT-B-16-plus-240.json','open_clip/model_configs'), # To save the sv_ttk.tcl file - MISSING IMPORT
# (venv_path + '/site-packages/open_clip/bpe_simple_vocab_16e6.txt.gz','open_clip')] if pathlib.Path(venv_path,"site-packages","open_clip").exists() else [] # To save the sv_ttk.tcl file - MISSING IMPORT],
a = Analysis(
['main.py'],
pathex=[],
Expand All @@ -31,19 +35,16 @@ a = Analysis(
( 'res/*', 'res'),
('ExternalSources', 'ExternalSources'),
('Extensions', 'Extensions'),
# THe following are picked from env variable. Please run python to include possible missing files
(venv_path + '/site-packages/sv_ttk/*','sv_ttk'), # To save the sv_ttk.tcl file - MISSING IMPORT
(venv_path + '/site-packages/sv_ttk/theme*','sv_ttk/theme'), # To save the sv_ttk.tcl file - MISSING IMPORT
] + open_clip_libs,
hiddenimports=['PIL._tkinter_finder','tkinterdnd2.TkinterDnD','slugify'],
hookspath=['MangaManager/pyinstaller_hooks'],
hooksconfig={},
runtime_hooks=[],
excludes=['torch','numpy','cv2'''],
excludes=['torch','numpy','cv2','open_clip','torchvision','torchaudio','tensorflow'],
win_no_prefer_redirects=False,
win_private_assemblies=False,
noarchive=False,
paths=[venv_path +"/site-packages"] # So it loads libraries from dev env first
# paths=[venv_path +"/site-packages"] # So it loads libraries from dev env first
# collect_all=True
)

Expand Down
14 changes: 11 additions & 3 deletions MangaManager/src/MetadataManager/CoverManager/torchlib.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import logging

"""
# pip requirements:
# OpenCV-Python
# sentence_transformers
# open_clip_torch
# requests
# git+https://github.com/openai/CLIP.git
# torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
"""
import logging



logger = logging.getLogger()

try:
raise ImportError
# raise ImportError
import PIL
import torch
import open_clip
Expand All @@ -23,6 +28,8 @@
logger.info("Torch libraries successfully imported")
# image processing model
device = "cuda" if torch.cuda.is_available() else "cpu"
if device == "cuda":
logger.warning("Using CUDA")
model, _, preprocess = open_clip.create_model_and_transforms('ViT-B-16-plus-240', pretrained="laion400m_e32")
model.to(device)
def imageEncoder(img):
Expand Down Expand Up @@ -50,6 +57,7 @@ def convert_PIL(pil_img: PIL.Image.Image):
return cvtColor(array(pil_img), COLOR_BGR2RGB)
except ImportError:
logger.warning("Missing dependecies for torch. disabling similarity")
logger.exception("Please install")


def convert_PIL(*_):
Expand Down

0 comments on commit e5dd1ab

Please sign in to comment.