Skip to content

Commit

Permalink
add: py2, py3 support
Browse files Browse the repository at this point in the history
1. setup tox
  • Loading branch information
kkweon committed Apr 30, 2017
1 parent d05555c commit 1108336
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 22 deletions.
8 changes: 4 additions & 4 deletions evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ def evaluate(prediction, true_labels):
Parameters
----------
prediction : 2-d array, shape (n_sample, n_classes)
prediction : 2-D array, shape (n_sample, n_classes)
Onehot encoded predicted array
true_labels : 2-d array, shape (n_sample, n_classes)
true_labels : 2-D array, shape (n_sample, n_classes)
Onehot encoded true array
Returns
Expand Down Expand Up @@ -53,13 +53,13 @@ def main():

# Check a single model accuracy
acc = evaluate(pred, y_test)
print(f"Model-{idx}: {acc:>.5%}")
print("Model-{}: {:>.5%}".format(idx, acc))

pred_list = np.asarray(pred_list)
pred_mean = np.mean(pred_list, 0)

accuracy = evaluate(pred_mean, y_test)
print(f"Final Test Accuracy: {accuracy:>.5%}")
print("Final Test Accuracy: {:>.5%}".format(accuracy))


if __name__ == '__main__':
Expand Down
4 changes: 2 additions & 2 deletions model.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import os

from keras.layers import Input
from keras.models import Model, load_model
from keras.models import Model
from keras.callbacks import ModelCheckpoint
from utils import train_generator


class BaseModel:
class BaseModel(object):
"""Base Model Interface
Methods
Expand Down
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Keras==2.0.4
numpy==1.12.1
tensorflow-gpu==1.1.0
h5py
2 changes: 1 addition & 1 deletion resnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def resnet(input_tensor):
y : softmax output
"""
def name_builder(type, stage, block, name):
return f"{type}{stage}{block}_branch{name}"
return "{}{}{}_branch{}".format(type, stage, block, name)

def identity_block(input_tensor, kernel_size, filters, stage, block):
F1, F2, F3 = filters
Expand Down
9 changes: 9 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env python

from distutils.core import setup

setup(name="mnist-competition",
version=1.0,
description="mnist competition file",
)

8 changes: 8 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[tox]
envlist = py2,py3,py35,py36

[testenv]
deps = -r{toxinidir}/requirements.txt
commands = python evaluation.py
usedevelop = True

2 changes: 1 addition & 1 deletion utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def train_generator():
return train_gen, val_gen


def plot_(model_path: str, file_path: str):
def plot_(model_path, file_path):
"""Visualize a model
Parameters
Expand Down
14 changes: 7 additions & 7 deletions vgg16.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,27 @@ def vgg(input_tensor):
y : softmax output tensor
"""
def two_conv_pool(x, F1, F2, name):
x = Conv2D(F1, (3, 3), activation=None, padding='same', name=f'{name}_conv1')(x)
x = Conv2D(F1, (3, 3), activation=None, padding='same', name='{}_conv1'.format(name))(x)
x = BatchNormalization()(x)
x = Activation('relu')(x)
x = Conv2D(F2, (3, 3), activation=None, padding='same', name=f'{name}_conv2')(x)
x = Conv2D(F2, (3, 3), activation=None, padding='same', name='{}_conv2'.format(name))(x)
x = BatchNormalization()(x)
x = Activation('relu')(x)
x = MaxPooling2D((2, 2), strides=(2, 2), name=f'{name}_pool')(x)
x = MaxPooling2D((2, 2), strides=(2, 2), name='{}_pool'.format(name))(x)

return x

def three_conv_pool(x, F1, F2, F3, name):
x = Conv2D(F1, (3, 3), activation=None, padding='same', name=f'{name}_conv1')(x)
x = Conv2D(F1, (3, 3), activation=None, padding='same', name='{}_conv1'.format(name))(x)
x = BatchNormalization()(x)
x = Activation('relu')(x)
x = Conv2D(F2, (3, 3), activation=None, padding='same', name=f'{name}_conv2')(x)
x = Conv2D(F2, (3, 3), activation=None, padding='same', name='{}_conv2'.format(name))(x)
x = BatchNormalization()(x)
x = Activation('relu')(x)
x = Conv2D(F3, (3, 3), activation=None, padding='same', name=f'{name}_conv3')(x)
x = Conv2D(F3, (3, 3), activation=None, padding='same', name='{}_conv3'.format(name))(x)
x = BatchNormalization()(x)
x = Activation('relu')(x)
x = MaxPooling2D((2, 2), strides=(2, 2), name=f'{name}_pool')(x)
x = MaxPooling2D((2, 2), strides=(2, 2), name='{}_pool'.format(name))(x)

return x

Expand Down
14 changes: 7 additions & 7 deletions vgg5.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,27 @@ def vgg(input_tensor):
y : softmax output tensor
"""
def two_conv_pool(x, F1, F2, name):
x = Conv2D(F1, (3, 3), activation=None, padding='same', name=f'{name}_conv1')(x)
x = Conv2D(F1, (3, 3), activation=None, padding='same', name='{}_conv1'.format(name))(x)
x = BatchNormalization()(x)
x = Activation('relu')(x)
x = Conv2D(F2, (3, 3), activation=None, padding='same', name=f'{name}_conv2')(x)
x = Conv2D(F2, (3, 3), activation=None, padding='same', name='{}_conv2'.format(name))(x)
x = BatchNormalization()(x)
x = Activation('relu')(x)
x = MaxPooling2D((2, 2), strides=(2, 2), name=f'{name}_pool')(x)
x = MaxPooling2D((2, 2), strides=(2, 2), name='{}_pool'.format(name))(x)

return x

def three_conv_pool(x, F1, F2, F3, name):
x = Conv2D(F1, (3, 3), activation=None, padding='same', name=f'{name}_conv1')(x)
x = Conv2D(F1, (3, 3), activation=None, padding='same', name='{}_conv1'.format(name))(x)
x = BatchNormalization()(x)
x = Activation('relu')(x)
x = Conv2D(F2, (3, 3), activation=None, padding='same', name=f'{name}_conv2')(x)
x = Conv2D(F2, (3, 3), activation=None, padding='same', name='{}_conv2'.format(name))(x)
x = BatchNormalization()(x)
x = Activation('relu')(x)
x = Conv2D(F3, (3, 3), activation=None, padding='same', name=f'{name}_conv3')(x)
x = Conv2D(F3, (3, 3), activation=None, padding='same', name='{}_conv3'.format(name))(x)
x = BatchNormalization()(x)
x = Activation('relu')(x)
x = MaxPooling2D((2, 2), strides=(2, 2), name=f'{name}_pool')(x)
x = MaxPooling2D((2, 2), strides=(2, 2), name='{}_pool'.format(name))(x)

return x

Expand Down

0 comments on commit 1108336

Please sign in to comment.