-
Notifications
You must be signed in to change notification settings - Fork 352
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
Docker demo support #81
Open
Fmstrat
wants to merge
6
commits into
krasserm:master
Choose a base branch
from
Fmstrat:docker
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
00b38c1
Docker demo support
Fmstrat 0aab497
Added nvidia support in docker
Fmstrat f1a3ebf
Removed 18.04 references from docker
Fmstrat c8368d6
Added div2k training in docker
Fmstrat 126b749
Switch docker training from Srgan to EDSR+Srgan
Fmstrat eacf877
Updated depth of documentation for SRGAN
Fmstrat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
data | ||
data.orig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
.ipynb_checkpoints | ||
.div2k | ||
.ckpt | ||
data | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
FROM ubuntu:20.04 | ||
|
||
WORKDIR /app | ||
|
||
COPY environment.yml /app | ||
|
||
RUN \ | ||
apt-get update &&\ | ||
DEBIAN_FRONTEND='noninteractive' apt-get install -y python wget nvidia-cuda-dev=10.1.243-3 nvidia-cuda-toolkit=10.1.243-3 &&\ | ||
wget https://martin-krasser.de/sisr/weights-edsr-16-x4.tar.gz &&\ | ||
wget https://martin-krasser.de/sisr/weights-wdsr-b-32-x4.tar.gz &&\ | ||
wget https://martin-krasser.de/sisr/weights-srgan.tar.gz &&\ | ||
tar xvfz weights-edsr-16-x4.tar.gz &&\ | ||
tar xvfz weights-wdsr-b-32-x4.tar.gz &&\ | ||
tar xvfz weights-srgan.tar.gz &&\ | ||
rm -f weights-edsr-16-x4.tar.gz &&\ | ||
rm -f weights-wdsr-b-32-x4.tar.gz &&\ | ||
rm -f weights-srgan.tar.gz &&\ | ||
wget https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64/libcudnn7_7.6.5.32-1+cuda10.1_amd64.deb &&\ | ||
wget https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64/libcudnn7-dev_7.6.5.32-1+cuda10.1_amd64.deb &&\ | ||
apt-get install -y ./libcudnn7_7.6.5.32-1+cuda10.1_amd64.deb &&\ | ||
apt-get install -y ./libcudnn7-dev_7.6.5.32-1+cuda10.1_amd64.deb &&\ | ||
rm -f ./libcudnn7_7.6.5.32-1+cuda10.1_amd64.deb &&\ | ||
rm -f ./libcudnn7-dev_7.6.5.32-1+cuda10.1_amd64.deb &&\ | ||
cd /root &&\ | ||
wget https://repo.anaconda.com/miniconda/Miniconda3-py39_4.9.2-Linux-x86_64.sh &&\ | ||
bash Miniconda3-py39_4.9.2-Linux-x86_64.sh -b &&\ | ||
rm -f Miniconda3-py39_4.9.2-Linux-x86_64.sh &&\ | ||
miniconda3/condabin/conda init bash &&\ | ||
bash -c " \ | ||
export PS1='$ ' &&\ | ||
. /root/.bashrc &&\ | ||
cd /app &&\ | ||
conda env create -f environment.yml \ | ||
" &&\ | ||
apt-get clean | ||
|
||
COPY model/ /app/model/ | ||
COPY *.py /app/ | ||
COPY LICENSE /app | ||
COPY docker/*.py /app/ | ||
COPY docker/run.sh /app | ||
|
||
ENTRYPOINT ["./run.sh"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import os | ||
import matplotlib.pyplot as plt | ||
|
||
from data import DIV2K | ||
from model.srgan import generator, discriminator | ||
from train import SrganTrainer, EdsrTrainer | ||
|
||
# %matplotlib inline | ||
|
||
# Location of model weights (needed for demo) | ||
weights_dir = '/data/weights/div2k' | ||
os.makedirs(weights_dir, exist_ok=True) | ||
weights_file = lambda filename: os.path.join(weights_dir, filename) | ||
|
||
# Set up images | ||
images_dir = '/data/images' | ||
os.makedirs(images_dir, exist_ok=True) | ||
caches_dir = '/data/caches' | ||
os.makedirs(caches_dir, exist_ok=True) | ||
div2k_train = DIV2K( | ||
scale=4, | ||
subset='train', | ||
downgrade='bicubic', | ||
images_dir=images_dir, | ||
caches_dir=caches_dir, | ||
) | ||
div2k_valid = DIV2K( | ||
scale=4, | ||
subset='valid', | ||
downgrade='bicubic', | ||
images_dir=images_dir, | ||
caches_dir=caches_dir, | ||
) | ||
|
||
# Do pre-training | ||
check_dir = f'/data/ckpt/pre_generator' | ||
os.makedirs(check_dir, exist_ok=True) | ||
train_ds = div2k_train.dataset(batch_size=16, random_transform=True) | ||
valid_ds = div2k_valid.dataset(batch_size=16, random_transform=True, repeat_count=1) | ||
pre_trainer = EdsrTrainer(model=generator(), checkpoint_dir=check_dir) | ||
pre_trainer.train( | ||
train_ds, | ||
valid_ds.take(1), | ||
#steps=1000000, | ||
steps=1000, | ||
evaluate_every=1000, | ||
save_best_only=False | ||
) | ||
pre_trainer.model.save_weights(weights_file('pre_generator.h5')) | ||
|
||
# Do gan-training | ||
gan_generator = generator() | ||
gan_generator.load_weights(weights_file('pre_generator.h5')) | ||
gan_trainer = SrganTrainer(generator=gan_generator, discriminator=discriminator()) | ||
gan_trainer.train( | ||
train_ds, | ||
#steps=200000 | ||
steps=100 | ||
) | ||
gan_trainer.generator.save_weights(weights_file('gan_generator.h5')) | ||
gan_trainer.discriminator.save_weights(weights_file('gan_discriminator.h5')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import os | ||
import sys | ||
import matplotlib.pyplot as plt | ||
|
||
from data import DIV2K | ||
from model.edsr import edsr | ||
|
||
from utils import load_image | ||
from model import resolve_single | ||
|
||
lr_image_path = sys.argv[1] | ||
|
||
# Number of residual blocks | ||
depth = 16 | ||
|
||
# Super-resolution factor | ||
scale = 4 | ||
|
||
weights_dir = f'weights/edsr-{depth}-x{scale}' | ||
weights_file = os.path.join(weights_dir, 'weights.h5') | ||
|
||
model = edsr(scale=scale, num_res_blocks=depth) | ||
model.load_weights(weights_file) | ||
|
||
lr = load_image(lr_image_path) | ||
sr = resolve_single(model, lr) | ||
|
||
fig = plt.figure() | ||
ax = plt.Axes(fig, [0., 0., 1., 1.]) | ||
ax.set_axis_off() | ||
fig.add_axes(ax) | ||
plt.imshow(sr) | ||
plt.savefig(sys.argv[1] + '_edsr.png', dpi=300, bbox_inches='tight', pad_inches=0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/bash | ||
|
||
export PS1='$ ' | ||
. /root/.bashrc | ||
|
||
export PATH=/usr/local/cuda-10.1/bin${PATH:+:${PATH}} | ||
export LD_LIBRARY_PATH=/usr/local/cuda-10.1/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}} | ||
|
||
conda activate sisr | ||
python ${1}.py "/working/${2}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import os | ||
import sys | ||
import matplotlib.pyplot as plt | ||
|
||
from data import DIV2K | ||
from model.srgan import generator | ||
|
||
from utils import load_image | ||
from model import resolve_single | ||
|
||
lr_image_path = sys.argv[1] | ||
|
||
weights_file = 'weights/srgan/gan_generator.h5' | ||
|
||
model = generator() | ||
model.load_weights(weights_file) | ||
|
||
lr = load_image(lr_image_path) | ||
sr = resolve_single(model, lr) | ||
|
||
fig = plt.figure() | ||
ax = plt.Axes(fig, [0., 0., 1., 1.]) | ||
ax.set_axis_off() | ||
fig.add_axes(ax) | ||
plt.imshow(sr) | ||
plt.savefig(sys.argv[1] + '_srgan.png', dpi=300, bbox_inches='tight', pad_inches=0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import os | ||
import sys | ||
import matplotlib.pyplot as plt | ||
|
||
from data import DIV2K | ||
from model.wdsr import wdsr_b | ||
|
||
from utils import load_image | ||
from model import resolve_single | ||
|
||
lr_image_path = sys.argv[1] | ||
|
||
# Number of residual blocks | ||
depth = 32 | ||
|
||
# Super-resolution factor | ||
scale = 4 | ||
|
||
weights_dir = f'weights/wdsr-b-{depth}-x{scale}' | ||
weights_file = os.path.join(weights_dir, 'weights.h5') | ||
|
||
model = wdsr_b(scale=scale, num_res_blocks=depth) | ||
model.load_weights(weights_file) | ||
|
||
lr = load_image(lr_image_path) | ||
sr = resolve_single(model, lr) | ||
|
||
fig = plt.figure() | ||
ax = plt.Axes(fig, [0., 0., 1., 1.]) | ||
ax.set_axis_off() | ||
fig.add_axes(ax) | ||
plt.imshow(sr) | ||
plt.savefig(sys.argv[1] + '_wdsr.png', dpi=300, bbox_inches='tight', pad_inches=0) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should start with
####
then? Also next section ...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't what? SRGAN? Is it a subset of WDSR (above it) or Pre-trained weights?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sections
Generator pre-training
andGenerator fine-tuning (GAN)
are subsections ofSRGAN
, so when you increase the level ofSRGAN
from##
to###
the levels of these subsections should be increased from###
to####
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I follow now! Updated: eacf877