Skip to content

Commit

Permalink
fix model-download-bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
bo-zhang-cs committed Jan 25, 2024
1 parent 45abbfe commit b6bd5c7
Show file tree
Hide file tree
Showing 53 changed files with 48 additions and 48 deletions.
15 changes: 14 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
./pyproject.toml
./pyproject.toml

/build
/dist
/*egg-info
*README_cn.md
zip_package.sh
**/__pycache__
**/pretrained_models
make_package.sh
**/shared_pretrained_models
*template*
**/*results
**/developer_readme.md
15 changes: 6 additions & 9 deletions libcom/utils/model_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def download_entire_folder(folder_path):

def download_file_from_network(file_name, save_dir):
if not os.path.exists(save_dir):
os.mkdir(save_dir)
os.mkdir(save_dir)
print('Try to download {} to {}'.format(file_name, save_dir))
try:
from huggingface_hub import hf_hub_download
Expand All @@ -51,8 +51,10 @@ def download_file_from_network(file_name, save_dir):
cache_dir=save_dir,
revision='master')
assert os.path.exists(file_path), 'Download {} failed, please try again'.format(file)
shutil.move(file_path, os.path.join(save_dir, file_name))

save_path = os.path.abspath(os.path.join(save_dir, file_name))
shutil.copyfile(os.path.abspath(file_path), save_path, follow_symlinks=True)
assert os.path.exists(save_path), 'Move file to {} failed, please try again'.format(save_path)
os.remove(os.path.realpath(file_path)) # delete the cache

if __name__ == '__main__':
file_list = ['BargainNet.pth', 'SOPA.pth']
Expand All @@ -63,9 +65,4 @@ def download_file_from_network(file_name, save_dir):

for folder in folder_list:
folder_path = './pretrained_models/' + folder
download_entire_folder(folder_path)





download_entire_folder(folder_path)
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def gen_packages_items():
return packages

def get_ext_modules():
# if encounter compilation issues, please refer to https://github.com/HuiZeng/Image-Adaptive-3DLUT?tab=readme-ov-file#build.
if torch.cuda.is_available():
return CUDAExtension('trilinear',
['libcom/image_harmonization/source/trilinear_cpp/src/trilinear_cuda.cpp',
Expand All @@ -107,7 +108,7 @@ def get_ext_modules():
cur_dir = os.path.dirname(os.path.abspath(__file__))
setup(
name='libcom',
version='0.0.1.post8',
version='0.0.1.post9',
description='Image Composition Toolbox',
long_description=readme(),
long_description_content_type='text/markdown',
Expand Down
Binary file added tests/source/background/1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/source/background/17.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added tests/source/background/8.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions tests/source/bbox/1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1000 895 1480 1355
1 change: 1 addition & 0 deletions tests/source/bbox/17.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
475 697 1275 1401

This file was deleted.

1 change: 0 additions & 1 deletion tests/source/bbox/35149c4895418040_m01yrx_e5b3a7bd_09.txt

This file was deleted.

1 change: 0 additions & 1 deletion tests/source/bbox/5b9e0751ca458cad_m0gjkl_40736b77_04.txt

This file was deleted.

1 change: 1 addition & 0 deletions tests/source/bbox/8.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1170 944 2331 3069
1 change: 0 additions & 1 deletion tests/source/bbox/8351494f79f6bf8f_m03k3r_73176af9_08.txt

This file was deleted.

1 change: 0 additions & 1 deletion tests/source/bbox/f80eda2459853824_m09g1w_b2413ec8_11.txt

This file was deleted.

Binary file added tests/source/composite/1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/source/composite/17.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added tests/source/composite/8.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file added tests/source/composite_mask/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/source/composite_mask/17.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added tests/source/composite_mask/8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file added tests/source/foreground/1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/source/foreground/17.jpg
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file added tests/source/foreground/8.jpg
Diff not rendered.
Diff not rendered.
Binary file added tests/source/foreground_mask/1.png
Binary file added tests/source/foreground_mask/17.png
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file added tests/source/foreground_mask/8.png
Diff not rendered.
Diff not rendered.
46 changes: 16 additions & 30 deletions tests/test_color_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,19 @@
task_name = 'color_transfer'

if __name__ == '__main__':
# test_set = get_test_list()
# result_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'results', task_name)
# if os.path.exists(result_dir):
# shutil.rmtree(result_dir)
# os.makedirs(result_dir, exist_ok=True)
# print(f'begin testing {task_name}...')
# for pair in test_set:
# comp_img, comp_mask = pair['composite'], pair['composite_mask']
# trans_img = color_transfer(comp_img, comp_mask)
# # visulization results
# img_name = os.path.basename(comp_img).replace('.png', '.jpg')
# grid_img = make_image_grid([comp_img, comp_mask, trans_img])
# res_path = os.path.join(result_dir, img_name)
# cv2.imwrite(res_path, grid_img)
# print('save result to ', res_path)
# print(f'end testing {task_name}!\n')

from libcom import color_transfer
from libcom.utils.process_image import make_image_grid
import cv2
comp_img1 = '../tests/source/composite/1.jpg'
comp_mask1 = '../tests/source/composite_mask/1.png'
trans_img1 = color_transfer(comp_img1, comp_mask1)
comp_img2 = '../tests/source/composite/8.jpg'
comp_mask2 = '../tests/source/composite_mask/8.png'
trans_img2 = color_transfer(comp_img2, comp_mask2)
# visualization results
grid_img = make_image_grid([comp_img1, comp_mask1, trans_img1,
comp_img2, comp_mask2, trans_img2], cols=3)
cv2.imwrite('../docs/_static/image/colortransfer_result1.jpg', grid_img)
test_set = get_test_list()
result_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'results', task_name)
if os.path.exists(result_dir):
shutil.rmtree(result_dir)
os.makedirs(result_dir, exist_ok=True)
print(f'begin testing {task_name}...')
for pair in test_set:
comp_img, comp_mask = pair['composite'], pair['composite_mask']
trans_img = color_transfer(comp_img, comp_mask)
# visulization results
img_name = os.path.basename(comp_img).replace('.png', '.jpg')
grid_img = make_image_grid([comp_img, comp_mask, trans_img])
res_path = os.path.join(result_dir, img_name)
cv2.imwrite(res_path, grid_img)
print('save result to ', res_path)
print(f'end testing {task_name}!\n')
9 changes: 7 additions & 2 deletions tests/test_painterly_image_harmonization.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@
os.makedirs(result_dir, exist_ok=True)
print(f'begin testing {task_name}...')
phd_net = PainterlyHarmonizationModel(device=0, model_type='PHDNet')
phdiff = PainterlyHarmonizationModel(device=0, model_type='PHDiffusion', use_residual=False)
phdiffres = PainterlyHarmonizationModel(device=0, model_type='PHDiffusion')
gpu_num = torch.cuda.device_count()
if gpu_num > 2:
phdiff_gpu, phdiffres_gpu = 1, 2
elif gpu_num > 1:
phdiff_gpu, phdiffres_gpu = 0, 1
phdiff = PainterlyHarmonizationModel(device=phdiff_gpu, model_type='PHDiffusion', use_residual=False)
phdiffres = PainterlyHarmonizationModel(device=phdiffres_gpu, model_type='PHDiffusion')
for pair in test_set:
comp_img, comp_mask = pair['composite'], pair['composite_mask']
phdnet_img = phd_net(comp_img, comp_mask)
Expand Down

0 comments on commit b6bd5c7

Please sign in to comment.