Skip to content

Commit bf1c931

Browse files
committed
first commit
0 parents  commit bf1c931

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+16079
-0
lines changed

.gitignore

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
# Compiled source #
2+
###################
3+
*.com
4+
*.class
5+
*.dll
6+
*.exe
7+
*.o
8+
*.so
9+
10+
# Packages #
11+
############
12+
# it's better to unpack these files and commit the raw source
13+
# git has its own built in compression methods
14+
*.7z
15+
*.dmg
16+
*.gz
17+
*.iso
18+
*.jar
19+
*.rar
20+
*.tar
21+
*.zip
22+
23+
# Logs and databases #
24+
######################
25+
*.log
26+
*.sql
27+
*.sqlite
28+
29+
# OS generated files #
30+
######################
31+
.DS_Store
32+
.DS_Store?
33+
._*
34+
.Spotlight-V100
35+
.Trashes
36+
ehthumbs.db
37+
Thumbs.db
38+
39+
# Perso #
40+
#########
41+
*.mat*
42+
data/
43+
saved_models/
44+
checkpoints/
45+
46+
# Byte-compiled / optimized / DLL files
47+
__pycache__/
48+
*.py[cod]
49+
*$py.class
50+
51+
# C extensions
52+
*.so
53+
54+
# Distribution / packaging
55+
.Python
56+
build/
57+
develop-eggs/
58+
dist/
59+
downloads/
60+
eggs/
61+
.eggs/
62+
lib/
63+
lib64/
64+
parts/
65+
sdist/
66+
var/
67+
wheels/
68+
share/python-wheels/
69+
*.egg-info/
70+
.installed.cfg
71+
*.egg
72+
MANIFEST
73+
74+
# PyInstaller
75+
# Usually these files are written by a python script from a template
76+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
77+
*.manifest
78+
*.spec
79+
80+
# Installer logs
81+
pip-log.txt
82+
pip-delete-this-directory.txt
83+
84+
# Unit test / coverage reports
85+
htmlcov/
86+
.tox/
87+
.nox/
88+
.coverage
89+
.coverage.*
90+
.cache
91+
nosetests.xml
92+
coverage.xml
93+
*.cover
94+
*.py,cover
95+
.hypothesis/
96+
.pytest_cache/
97+
cover/
98+
99+
# Translations
100+
*.mo
101+
*.pot
102+
103+
# Django stuff:
104+
*.log
105+
local_settings.py
106+
db.sqlite3
107+
db.sqlite3-journal
108+
109+
# Flask stuff:
110+
instance/
111+
.webassets-cache
112+
113+
# Scrapy stuff:
114+
.scrapy
115+
116+
# Sphinx documentation
117+
docs/_build/
118+
119+
# PyBuilder
120+
.pybuilder/
121+
target/
122+
123+
# Jupyter Notebook
124+
.ipynb_checkpoints
125+
126+
# IPython
127+
profile_default/
128+
ipython_config.py
129+
130+
# pyenv
131+
# For a library or package, you might want to ignore these files since the code is
132+
# intended to run in multiple environments; otherwise, check them in:
133+
# .python-version
134+
135+
# pipenv
136+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
137+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
138+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
139+
# install all needed dependencies.
140+
#Pipfile.lock
141+
142+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
143+
__pypackages__/
144+
145+
# Celery stuff
146+
celerybeat-schedule
147+
celerybeat.pid
148+
149+
# SageMath parsed files
150+
*.sage.py
151+
152+
# Environments
153+
.env
154+
.venv
155+
env/
156+
venv/
157+
ENV/
158+
env.bak/
159+
venv.bak/
160+
161+
# Spyder project settings
162+
.spyderproject
163+
.spyproject
164+
165+
# Rope project settings
166+
.ropeproject
167+
168+
# mkdocs documentation
169+
/site
170+
171+
# mypy
172+
.mypy_cache/
173+
.dmypy.json
174+
dmypy.json
175+
176+
# Pyre type checker
177+
.pyre/
178+
179+
# pytype static type analyzer
180+
.pytype/
181+
182+
# Cython debug symbols
183+
cython_debug/

AdvGAN/activations.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
"""
4+
Created on Thu Jan 17 08:39:05 2019
5+
6+
@author: vicari
7+
"""
8+
import tensorflow as tf
9+
import numpy as np
10+
11+
def MaxMin():
12+
def f(x):
13+
shape = x.get_shape().as_list()
14+
shape[0] = -1
15+
group = tf.reshape(x,[-1, 2])
16+
a,b = tf.split(group, 2, 1)
17+
c = tf.concat((tf.minimum(a,b), tf.maximum(b,a)), axis=1)
18+
res = tf.reshape(c,shape)
19+
return res
20+
21+
return lambda x : f(x)
22+
23+
def FullSort():
24+
def f(x):
25+
shape = x.get_shape().as_list()
26+
res = -tf.nn.top_k(-x, k=shape[-1])[0]
27+
return res
28+
29+
return lambda x : f(x)
30+
31+
def lrelu(l=0.2):
32+
return lambda x : tf.nn.leaky_relu(x,l)
33+
34+
def relu():
35+
return lambda x : tf.nn.relu(x)

AdvGAN/classifiers.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
"""
4+
Created on Mon Apr 1 09:40:23 2019
5+
6+
@author: vicari
7+
"""
8+
9+
from AdvGAN import utils, dataset, cyclegan, models, print_functions, activations, layers
10+
11+
import tensorflow as tf
12+
from tensorflow.layers import Flatten
13+
14+
from tensorflow import keras
15+
16+
from tensorflow.python.keras.datasets import cifar10
17+
from tensorflow.python.keras.preprocessing.image import ImageDataGenerator
18+
from tensorflow.python.keras.models import Sequential
19+
from tensorflow.python.keras.layers import Dense, Dropout, Activation, Flatten
20+
from tensorflow.python.keras.layers import Conv2D, MaxPooling2D
21+
22+
def keras_conv_net(input_shape, num_classes=10):
23+
model = Sequential()
24+
model.add(Conv2D(32, (3, 3), padding='same',
25+
input_shape=input_shape))
26+
model.add(Activation('relu'))
27+
model.add(Conv2D(32, (3, 3)))
28+
model.add(Activation('relu'))
29+
model.add(MaxPooling2D(pool_size=(2, 2)))
30+
model.add(Dropout(0.25))
31+
32+
model.add(Conv2D(64, (3, 3), padding='same'))
33+
model.add(Activation('relu'))
34+
model.add(Conv2D(64, (3, 3)))
35+
model.add(Activation('relu'))
36+
model.add(MaxPooling2D(pool_size=(2, 2)))
37+
model.add(Dropout(0.25))
38+
39+
model.add(Flatten())
40+
model.add(Dense(512))
41+
model.add(Activation('relu'))
42+
model.add(Dropout(0.5))
43+
model.add(Dense(num_classes))
44+
model.add(Activation('softmax'))
45+
46+
# initiate RMSprop optimizer
47+
opt = keras.optimizers.RMSprop(lr=0.0001, decay=1e-6)
48+
49+
# Let's train the model using RMSprop
50+
model.compile(loss='categorical_crossentropy',
51+
optimizer=opt,
52+
metrics=['accuracy'])
53+
54+
return model
55+
56+
def make_simple_conv_net(nb_class=10):
57+
def simple_conv_net(X, scope_name='classifier_conv_net', reuse=False):
58+
59+
with tf.variable_scope(scope_name, reuse) as scope:
60+
61+
if reuse:
62+
scope.reuse_variables()
63+
64+
net = layers.conv2D(X, 3, 64, 1, name='conv0_1', batch_normed=True)
65+
net = tf.nn.relu(net)
66+
67+
net = layers.conv2D(net, 4, 64, 2, name='conv0_2', batch_normed=True)
68+
net = tf.nn.relu(net)
69+
70+
net = layers.conv2D(X, 3, 128, 1, name='conv1_1', batch_normed=True)
71+
net = tf.nn.relu(net)
72+
73+
net = layers.conv2D(net, 4, 128, 2, name='conv1_2', batch_normed=True)
74+
net = tf.nn.relu(net)
75+
76+
net = layers.conv2D(X, 3, 256, 1, name='conv2_1', batch_normed=True)
77+
net = tf.nn.relu(net)
78+
79+
net = layers.conv2D(net, 4, 256, 2, name='conv2_2', batch_normed=True)
80+
net = tf.nn.relu(net)
81+
net = Flatten()(net)
82+
83+
net = layers.linear(net, nb_class, name='dense_layer')
84+
85+
net = tf.nn.softmax(net)
86+
87+
return net
88+
89+
return simple_conv_net

0 commit comments

Comments
 (0)