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

Update to the latest torch #103

Open
wants to merge 2 commits into
base: master
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ notebooks/.ipynb_checkpoints/*
*.zip
*.pkl
*.pyc

# Add the images explicitly
*.jpg
*.png
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "segmentation"]
path = segmentation
url = https://github.com/mingyuliutw/semantic-segmentation-pytorch
9 changes: 9 additions & 0 deletions demo_example3.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# The model paths are coming from the demo defined here:
# https://github.com/mingyuliutw/semantic-segmentation-pytorch
git submodule update --init --recursive

pushd segmentation
echo -e "\033[33m[WARN]\033[0m Segmentation repo might have dependency on the older version of Pytorch"
./demo_test.sh
popd

mkdir images -p && mkdir results -p;
rm images/content3.png -rf;
rm images/style3.png -rf;
Expand Down
3 changes: 2 additions & 1 deletion demo_with_ade20k_ssn.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
from segmentation.models import ModelBuilder, SegmentationModule
from lib.nn import user_scattered_collate, async_copy_to
from lib.utils import as_numpy, mark_volatile
from scipy.misc import imread, imresize
# from scipy.misc import imread, imresize
from imageio import imread
import cv2
from torchvision import transforms
import numpy as np
Expand Down
19 changes: 13 additions & 6 deletions photo_smooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""
from __future__ import division
import torch.nn as nn
import scipy.misc
# import scipy.misc
import numpy as np
import scipy.sparse
import scipy.sparse.linalg
Expand All @@ -20,13 +20,15 @@ def __init__(self, beta=0.9999):
def process(self, initImg, contentImg):

if type(contentImg) == str:
content = scipy.misc.imread(contentImg, mode='RGB')
# content = scipy.misc.imread(contentImg, mode='RGB')
content = imageio.imread(contentImg, format='RGB')
else:
content = contentImg.copy()
# content = scipy.misc.imread(contentImg, mode='RGB')

if type(initImg) == str:
B = scipy.misc.imread(initImg, mode='RGB').astype(np.float64) / 255
# B = scipy.misc.imread(initImg, mode='RGB').astype(np.float64) / 255
B = imageio.imread(initImg, mode='RGB').astype(np.float64) / 255
else:
B = scipy.asarray(initImg).astype(np.float64) / 255
# B = self.
Expand All @@ -35,7 +37,12 @@ def process(self, initImg, contentImg):
h = h1 - 4
w = w1 - 4
B = B[int((h1-h)/2):int((h1-h)/2+h),int((w1-w)/2):int((w1-w)/2+w),:]
content = scipy.misc.imresize(content,(h,w))
# content = scipy.misc.imresize(content,(h,w))
if isinstance(content, Image.Image):
content = content.resize((h, w))
else:
content = Image.fromarray(content).resize((h, w))
content = np.array(content)
B = self.__replication_padding(B,2)
content = self.__replication_padding(content,2)
content = content.astype(np.float64)/255
Expand All @@ -57,7 +64,7 @@ def process(self, initImg, contentImg):
V = V*(1-self.beta)
V = V.reshape(h1,w1,k)
V = V[2:2+h,2:2+w,:]

img = Image.fromarray(np.uint8(np.clip(V * 255., 0, 255.)))
return img

Expand Down Expand Up @@ -96,4 +103,4 @@ def __replication_padding(self, arr,pad):
def __rolling_block(self, A, block=(3, 3)):
shape = (A.shape[0] - block[0] + 1, A.shape[1] - block[1] + 1) + block
strides = (A.strides[0], A.strides[1]) + A.strides
return as_strided(A, shape=shape, strides=strides)
return as_strided(A, shape=shape, strides=strides)
7 changes: 7 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
torch>=1.5.1
torchvision>=0.6
scikit-umfpack
setuptools
cupy-cuda101
pynvrtc
opencv-contrib-python
Loading