Skip to content

Commit e5be19f

Browse files
committed
Initial commit
- Add basic files (.gitignore, requirements.txt) - Create some hyperparameters - Create preprocessing functions
0 parents  commit e5be19f

7 files changed

+361
-0
lines changed

.gitignore

+253
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,253 @@
1+
2+
# Created by https://www.toptal.com/developers/gitignore/api/visualstudiocode,macos,windows,linux,git,virtualenv,python
3+
# Edit at https://www.toptal.com/developers/gitignore?templates=visualstudiocode,macos,windows,linux,git,virtualenv,python
4+
5+
### Git ###
6+
# Created by git for backups. To disable backups in Git:
7+
# $ git config --global mergetool.keepBackup false
8+
*.orig
9+
10+
# Created by git when using merge tools for conflicts
11+
*.BACKUP.*
12+
*.BASE.*
13+
*.LOCAL.*
14+
*.REMOTE.*
15+
*_BACKUP_*.txt
16+
*_BASE_*.txt
17+
*_LOCAL_*.txt
18+
*_REMOTE_*.txt
19+
20+
### Linux ###
21+
*~
22+
23+
# temporary files which can be created if a process still has a handle open of a deleted file
24+
.fuse_hidden*
25+
26+
# KDE directory preferences
27+
.directory
28+
29+
# Linux trash folder which might appear on any partition or disk
30+
.Trash-*
31+
32+
# .nfs files are created when an open file is removed but is still being accessed
33+
.nfs*
34+
35+
### macOS ###
36+
# General
37+
.DS_Store
38+
.AppleDouble
39+
.LSOverride
40+
41+
# Icon must end with two \r
42+
Icon
43+
44+
45+
# Thumbnails
46+
._*
47+
48+
# Files that might appear in the root of a volume
49+
.DocumentRevisions-V100
50+
.fseventsd
51+
.Spotlight-V100
52+
.TemporaryItems
53+
.Trashes
54+
.VolumeIcon.icns
55+
.com.apple.timemachine.donotpresent
56+
57+
# Directories potentially created on remote AFP share
58+
.AppleDB
59+
.AppleDesktop
60+
Network Trash Folder
61+
Temporary Items
62+
.apdisk
63+
64+
### Python ###
65+
# Byte-compiled / optimized / DLL files
66+
__pycache__/
67+
*.py[cod]
68+
*$py.class
69+
70+
# C extensions
71+
*.so
72+
73+
# Distribution / packaging
74+
.Python
75+
build/
76+
develop-eggs/
77+
dist/
78+
downloads/
79+
eggs/
80+
.eggs/
81+
lib/
82+
lib64/
83+
parts/
84+
sdist/
85+
var/
86+
wheels/
87+
pip-wheel-metadata/
88+
share/python-wheels/
89+
*.egg-info/
90+
.installed.cfg
91+
*.egg
92+
MANIFEST
93+
94+
# PyInstaller
95+
# Usually these files are written by a python script from a template
96+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
97+
*.manifest
98+
*.spec
99+
100+
# Installer logs
101+
pip-log.txt
102+
pip-delete-this-directory.txt
103+
104+
# Unit test / coverage reports
105+
htmlcov/
106+
.tox/
107+
.nox/
108+
.coverage
109+
.coverage.*
110+
.cache
111+
nosetests.xml
112+
coverage.xml
113+
*.cover
114+
*.py,cover
115+
.hypothesis/
116+
.pytest_cache/
117+
pytestdebug.log
118+
119+
# Translations
120+
*.mo
121+
*.pot
122+
123+
# Django stuff:
124+
*.log
125+
local_settings.py
126+
db.sqlite3
127+
db.sqlite3-journal
128+
129+
# Flask stuff:
130+
instance/
131+
.webassets-cache
132+
133+
# Scrapy stuff:
134+
.scrapy
135+
136+
# Sphinx documentation
137+
docs/_build/
138+
doc/_build/
139+
140+
# PyBuilder
141+
target/
142+
143+
# Jupyter Notebook
144+
.ipynb_checkpoints
145+
146+
# IPython
147+
profile_default/
148+
ipython_config.py
149+
150+
# pyenv
151+
.python-version
152+
153+
# pipenv
154+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
155+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
156+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
157+
# install all needed dependencies.
158+
#Pipfile.lock
159+
160+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
161+
__pypackages__/
162+
163+
# Celery stuff
164+
celerybeat-schedule
165+
celerybeat.pid
166+
167+
# SageMath parsed files
168+
*.sage.py
169+
170+
# Environments
171+
.env
172+
.venv
173+
env/
174+
venv/
175+
ENV/
176+
env.bak/
177+
venv.bak/
178+
pythonenv*
179+
180+
# Spyder project settings
181+
.spyderproject
182+
.spyproject
183+
184+
# Rope project settings
185+
.ropeproject
186+
187+
# mkdocs documentation
188+
/site
189+
190+
# mypy
191+
.mypy_cache/
192+
.dmypy.json
193+
dmypy.json
194+
195+
# Pyre type checker
196+
.pyre/
197+
198+
# pytype static type analyzer
199+
.pytype/
200+
201+
# profiling data
202+
.prof
203+
204+
### VirtualEnv ###
205+
# Virtualenv
206+
# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/
207+
[Bb]in
208+
[Ii]nclude
209+
[Ll]ib
210+
[Ll]ib64
211+
[Ll]ocal
212+
[Ss]cripts
213+
pyvenv.cfg
214+
pip-selfcheck.json
215+
216+
### VisualStudioCode ###
217+
.vscode/*
218+
!.vscode/tasks.json
219+
!.vscode/launch.json
220+
*.code-workspace
221+
222+
### VisualStudioCode Patch ###
223+
# Ignore all local history of files
224+
.history
225+
.ionide
226+
227+
### Windows ###
228+
# Windows thumbnail cache files
229+
Thumbs.db
230+
Thumbs.db:encryptable
231+
ehthumbs.db
232+
ehthumbs_vista.db
233+
234+
# Dump file
235+
*.stackdump
236+
237+
# Folder config file
238+
[Dd]esktop.ini
239+
240+
# Recycle Bin used on file shares
241+
$RECYCLE.BIN/
242+
243+
# Windows Installer files
244+
*.cab
245+
*.msi
246+
*.msix
247+
*.msm
248+
*.msp
249+
250+
# Windows shortcuts
251+
*.lnk
252+
253+
# End of https://www.toptal.com/developers/gitignore/api/visualstudiocode,macos,windows,linux,git,virtualenv,python

LICENCE

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright 2020 Eddy Decena
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

cycle/__init__.py

Whitespace-only changes.

cycle/config.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# original image size for cycle_gan/horse2zebra dataset
2+
ORIG_IMG_SIZE = (286, 286)
3+
4+
# Random Crop
5+
INPUT_IMG_SIZE = (256, 256, 3)
6+
7+
8+
BATCH_SIZE = 1
9+
BUFFER_SIZE = 256

cycle/preprocessing.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import tensorflow as tf
2+
3+
# Hyperparameters
4+
from cycle.config import ORIG_IMG_SIZE
5+
from cycle.config import INPUT_IMG_SIZE
6+
7+
def normalize_img(img):
8+
img = tf.cast(img, tf.float32)
9+
return (img / 127.5) - 1.0
10+
11+
def preprocess_train_image(img, label):
12+
img = tf.image.random_flip_left_right(img)
13+
img = tf.image.resize(img, [*ORIG_IMG_SIZE])
14+
img = tf.image.random_crop(img, [*INPUT_IMG_SIZE])
15+
return normalize_img(img)
16+
17+
def preprocess_test_image(img, label):
18+
img = tf.image.resize(img, [INPUT_IMG_SIZE[0], INPUT_IMG_SIZE[1]])
19+
return normalize_img(img)

requirements.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
tensorflow==2.3.0
2+
numpy==1.19.4
3+
matplotlib==3.3.2
4+
tensorflow-addons==0.11.2
5+
tensorflow-datasets==4.1.0

train.py

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import os
2+
3+
import numpy as np
4+
import matplotlib.pyplot as plt
5+
import tensorflow_datasets as tfds
6+
from tensorflow.data.experimental import AUTOTUNE
7+
8+
# Hyperparameters
9+
from cycle.config import ORIG_IMG_SIZE
10+
from cycle.config import INPUT_IMG_SIZE
11+
from cycle.config import BUFFER_SIZE
12+
from cycle.config import BATCH_SIZE
13+
14+
from cycle.preprocessing import preprocess_train_image
15+
from cycle.preprocessing import preprocess_test_image
16+
17+
datasets = tfds.load('cycle_gan/horse2zebra', as_supervised=True)
18+
19+
train_horses, train_zebras = datasets['trainA'], datasets['trainB']
20+
test_horses, test_zebras = datasets['testA'], datasets['testB']
21+
22+
# Apply preprocessing
23+
24+
train_horses = (
25+
train_horses.map(preprocess_train_image, num_parallel_calls=AUTOTUNE)
26+
.cache()
27+
.shuffle(BUFFER_SIZE)
28+
.batch(BATCH_SIZE)
29+
)
30+
31+
train_zebras = (
32+
train_zebras.map(preprocess_train_image, num_parallel_calls=AUTOTUNE)
33+
.cache()
34+
.shuffle(BUFFER_SIZE)
35+
.batch(BATCH_SIZE)
36+
)
37+
38+
39+
test_horses = (
40+
test_horses.map(preprocess_test_image, num_parallel_calls=AUTOTUNE)
41+
.cache()
42+
.shuffle(BUFFER_SIZE)
43+
.batch(BATCH_SIZE)
44+
)
45+
46+
test_zebras = (
47+
test_zebras.map(preprocess_test_image, num_parallel_calls=AUTOTUNE)
48+
.cache()
49+
.shuffle(BUFFER_SIZE)
50+
.batch(BATCH_SIZE)
51+
)
52+
53+
_, ax_train = plt.subplots(4, 2, figsize=(10, 15))
54+
for i, samples in enumerate(zip(train_horses.take(4), train_zebras.take(4))):
55+
horse = (((samples[0][0] * 127.5) + 127.5).numpy()).astype(np.uint8)
56+
zebra = (((samples[1][0] * 127.5) + 127.5).numpy()).astype(np.uint8)
57+
ax_train[i, 0].imshow(horse)
58+
ax_train[i, 1].imshow(zebra)
59+
plt.show()
60+
61+
_, ax_test = plt.subplots(4, 2, figsize=(10, 15))
62+
for i, samples in enumerate(zip(test_horses.take(4), test_zebras.take(4))):
63+
horse = (((samples[0][0] * 127.5) + 127.5).numpy()).astype(np.uint8)
64+
zebra = (((samples[1][0] * 127.5) + 127.5).numpy()).astype(np.uint8)
65+
ax_test[i, 0].imshow(horse)
66+
ax_test[i, 1].imshow(zebra)
67+
plt.show()
68+

0 commit comments

Comments
 (0)