Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
maximkm committed Aug 31, 2021
1 parent fd61f77 commit 8d62bd8
Show file tree
Hide file tree
Showing 162 changed files with 17 additions and 12 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ For more detailed information on configuring configs, see the wiki page [configu

## Examples of generation

Many launches were conducted for the selection of hyperparameters and testing, the result of training one of the StyleGAN launches with a resolution of 64x64 after 1 day of training on 1 x Tesla V100, on a dataset of 20k images with a resolution of 64x64, is shown below.
Many launches were conducted for the selection of hyperparameters and testing, the result of training one of the StyleGAN launches with a resolution of 64x64 after 1 day of training on 4 x Tesla V100, on a dataset of 20k images with a resolution of 64x64, is shown below.

<img src="img/64x64 ex1.png" alt="StyleGAN 64" width="700"/>
<img src="img/64x64 ex1.png" alt="StyleGAN 64" width="900"/>

Also, the result of training the StyleGAN model for a resolution of 256x256, which was trained for 1.5 days on a 4 x Tesla V100, on a dataset of 92k images with a resolution of 256x256, is shown below:

<img src="img/256x256 ex1.png" alt="StyleGAN 256" width="700"/>
<img src="img/256x256 ex1.png" alt="StyleGAN 256" width="900"/>

The images are obtained by denormalization, so their saturation can be adjusted

Expand All @@ -91,13 +91,13 @@ SaveImages(Trainer, dir='img', cnt=10)
Example of creating a video using the example of interpolation between two images:

```python
from utils.video import generate_video
from utils.video import GenerateVideo

samples = from_to_video(z_1, z_2) # A tensor consisting of image frames
generate_video(samples)
samples = FromToVideo(z_1, z_2) # A tensor consisting of image frames
GenerateVideo(samples)
```

<img src="img/interpolate.gif" alt="StyleGAN 256" width="250"/>
<img src="img/interpolate.gif" alt="StyleGAN 256" width="350"/>

## Detailed information on the implementation

Expand Down
Binary file modified img/64x64 ex1.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 removed img/64x64/1.png
Binary file not shown.
Binary file modified img/64x64/10.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 img/64x64/100.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 img/64x64/104.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 img/64x64/106.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 modified img/64x64/11.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 img/64x64/1148.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 img/64x64/1179.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 img/64x64/118.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 img/64x64/119.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 modified img/64x64/12.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 img/64x64/124.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 removed img/64x64/13.png
Binary file not shown.
Binary file removed img/64x64/14.png
Binary file not shown.
Binary file added img/64x64/1434.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 img/64x64/1437.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 img/64x64/146.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 removed img/64x64/15.png
Binary file not shown.
Binary file added img/64x64/1518.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 img/64x64/1581.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 img/64x64/1582.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 removed img/64x64/16.png
Binary file not shown.
Binary file added img/64x64/1635.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 img/64x64/1686.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 removed img/64x64/17.png
Diff not rendered.
Binary file added img/64x64/175.png
Binary file removed img/64x64/18.png
Diff not rendered.
Binary file added img/64x64/188.png
Binary file removed img/64x64/19.png
Diff not rendered.
Binary file added img/64x64/1924.png
Binary file added img/64x64/194.png
Binary file added img/64x64/1945.png
Binary file added img/64x64/1952.png
Binary file added img/64x64/197.png
Binary file modified img/64x64/2.png
Binary file removed img/64x64/20.png
Diff not rendered.
Binary file added img/64x64/202.png
Binary file added img/64x64/2028.png
Binary file added img/64x64/2031.png
Binary file added img/64x64/2032.png
Binary file added img/64x64/2037.png
Binary file added img/64x64/2041.png
Binary file added img/64x64/2042.png
Binary file added img/64x64/2048.png
Binary file added img/64x64/205.png
Binary file added img/64x64/2099.png
Binary file added img/64x64/210.png
Binary file added img/64x64/213.png
Binary file added img/64x64/2139.png
Binary file added img/64x64/2166.png
Binary file added img/64x64/2169.png
Binary file added img/64x64/2187.png
Binary file added img/64x64/219.png
Binary file added img/64x64/2200.png
Binary file added img/64x64/2229.png
Binary file added img/64x64/223.png
Binary file added img/64x64/2230.png
Binary file added img/64x64/2232.png
Binary file added img/64x64/2270.png
Binary file added img/64x64/2275.png
Binary file added img/64x64/23.png
Binary file added img/64x64/232.png
Binary file added img/64x64/237.png
Binary file added img/64x64/238.png
Binary file added img/64x64/245.png
Binary file added img/64x64/2455.png
Binary file added img/64x64/246.png
Binary file added img/64x64/2489.png
Binary file added img/64x64/2490.png
Binary file added img/64x64/2506.png
Binary file added img/64x64/2634.png
Binary file added img/64x64/2649.png
Binary file added img/64x64/2765.png
Binary file added img/64x64/2999.png
Binary file removed img/64x64/3.png
Diff not rendered.
Binary file added img/64x64/301.png
Binary file added img/64x64/3028.png
Binary file added img/64x64/3034.png
Binary file added img/64x64/3086.png
Binary file added img/64x64/3091.png
Binary file added img/64x64/3094.png
Binary file added img/64x64/3104.png
Binary file added img/64x64/311.png
Binary file added img/64x64/320.png
Binary file added img/64x64/321.png
Binary file added img/64x64/325.png
Binary file added img/64x64/3279.png
Binary file added img/64x64/3293.png
Binary file added img/64x64/333.png
Binary file added img/64x64/3343.png
Binary file added img/64x64/3371.png
Binary file modified img/64x64/4.png
Binary file added img/64x64/414.png
Binary file added img/64x64/4188.png
Binary file added img/64x64/4189.png
Binary file added img/64x64/42.png
Binary file added img/64x64/44.png
Binary file added img/64x64/4409.png
Binary file added img/64x64/4553.png
Binary file added img/64x64/497.png
Binary file removed img/64x64/5.png
Diff not rendered.
Binary file added img/64x64/5233.png
Binary file added img/64x64/5414.png
Binary file added img/64x64/5459.png
Binary file added img/64x64/5928.png
Binary file removed img/64x64/6.png
Diff not rendered.
Binary file added img/64x64/6022.png
Binary file added img/64x64/6547.png
Binary file added img/64x64/6816.png
Binary file added img/64x64/6964.png
Binary file added img/64x64/6986.png
Binary file removed img/64x64/7.png
Diff not rendered.
Binary file added img/64x64/7077.png
Binary file added img/64x64/7138.png
Binary file added img/64x64/7185.png
Binary file added img/64x64/7230.png
Binary file added img/64x64/7537.png
Binary file added img/64x64/7584.png
Binary file removed img/64x64/8.png
Diff not rendered.
Binary file added img/64x64/8105.png
Binary file added img/64x64/8116.png
Binary file added img/64x64/8199.png
Binary file added img/64x64/8671.png
Binary file added img/64x64/8672.png
Binary file added img/64x64/8702.png
Binary file added img/64x64/8775.png
Binary file added img/64x64/8786.png
Binary file added img/64x64/8838.png
Binary file added img/64x64/8842.png
Binary file added img/64x64/8924.png
Binary file added img/64x64/8925.png
Binary file added img/64x64/8948.png
Binary file added img/64x64/8953.png
Binary file removed img/64x64/9.png
Diff not rendered.
Binary file added img/64x64/9012.png
Binary file added img/64x64/9015.png
Binary file added img/64x64/9020.png
Binary file added img/64x64/9050.png
Binary file added img/64x64/9165.png
Binary file added img/64x64/9262.png
Binary file added img/64x64/9365.png
Binary file added img/64x64/9396.png
Binary file added img/64x64/9415.png
Binary file added img/64x64/9437.png
Binary file added img/64x64/9557.png
Binary file added img/64x64/96.png
Binary file added img/64x64/9699.png
Binary file added img/64x64/97.png
Binary file added img/64x64/99.png
Binary file added img/64x64/9900.png
Binary file added img/64x64/9919.png
Binary file added img/64x64/9924.png
Binary file added img/64x64/9939.png
Binary file added img/64x64/9975.png
Binary file added img/64x64/9976.png
Binary file modified img/interpolate.gif
Binary file added img/interpolate.mp4
Binary file not shown.
9 changes: 7 additions & 2 deletions start.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
import os


def dynamic_import(module):
return importlib.import_module(module)
def dynamic_import(name):
module = importlib.import_module(name)
importlib.reload(module)
return module


def get_py_modules(files_dir):
Expand Down Expand Up @@ -91,6 +93,9 @@ def init_train(path_to_config, wandb_set=False, load_dataset=True):
last_epoch = epochs[-1]
print(f'{conf["Weight_dir"]}/weight {last_epoch}.pth')
state = torch.load(f'{conf["Weight_dir"]}/weight {last_epoch}.pth')
del_module = lambda key: key if 'module.' != key[:7] else key[7:]
state['G'] = {del_module(key): value for key, value in state['G'].items()}
state['D'] = {del_module(key): value for key, value in state['D'].items()}
print(f'Load the pre-trained weight {last_epoch}')
G.load_state_dict(state['G'])
D.load_state_dict(state['D'])
Expand Down
4 changes: 2 additions & 2 deletions utils/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ def TensorToImage(img, mean=0.5, std=0.375):


def SaveImages(Trainer, dir='img', cnt=1, mean=0.5, std=0.375):
TensorImages = Trainer.generate_images(cnt)
if not os.path.exists(dir):
os.makedirs(dir)
for n, img in enumerate(TensorImages, 1):
for n in range(cnt):
img = Trainer.generate_images()[0]
image = Image.fromarray(TensorToImage(img.detach().cpu(), mean, std))
image.save(f'{dir}/{n}.png')
2 changes: 1 addition & 1 deletion utils/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from matplotlib import animation, pyplot as plt


def generate_video(samples_list, delay=1000):
def GenerateVideo(samples_list, delay=1000):
def process_image(img):
if len(img.shape) == 4:
img = img[0]
Expand Down

0 comments on commit 8d62bd8

Please sign in to comment.