Skip to content
This repository has been archived by the owner on Jul 5, 2021. It is now read-only.

Commit

Permalink
File and folder restructuring for more organized code
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeSeif committed Sep 2, 2018
1 parent a3012fb commit 6e4eb72
Show file tree
Hide file tree
Showing 31 changed files with 41 additions and 45 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
*.pyc
*.graph
models/*.graph
models/*.pyc
models/*.ckpt*
models/*.pb
Expand Down
Empty file added builders/__init__.py
Empty file.
6 changes: 3 additions & 3 deletions models/frontend_builder.py → builders/frontend_builder.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import tensorflow as tf
from tensorflow.contrib import slim
import resnet_v2
import mobilenet_v2
import inception_v4
from frontends import resnet_v2
from frontends import mobilenet_v2
from frontends import inception_v4
import os


Expand Down
27 changes: 14 additions & 13 deletions model_builder.py → builders/model_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,29 @@
import subprocess

sys.path.append("models")
from FC_DenseNet_Tiramisu import build_fc_densenet
from Encoder_Decoder import build_encoder_decoder
from RefineNet import build_refinenet
from FRRN import build_frrn
from MobileUNet import build_mobile_unet
from PSPNet import build_pspnet
from GCN import build_gcn
from DeepLabV3 import build_deeplabv3
from DeepLabV3_plus import build_deeplabv3_plus
from AdapNet import build_adaptnet
from models.FC_DenseNet_Tiramisu import build_fc_densenet
from models.Encoder_Decoder import build_encoder_decoder
from models.RefineNet import build_refinenet
from models.FRRN import build_frrn
from models.MobileUNet import build_mobile_unet
from models.PSPNet import build_pspnet
from models.GCN import build_gcn
from models.DeepLabV3 import build_deeplabv3
from models.DeepLabV3_plus import build_deeplabv3_plus
from models.AdapNet import build_adaptnet
from models.custom_model import build_custom

SUPPORTED_MODELS = ["FC-DenseNet56", "FC-DenseNet67", "FC-DenseNet103", "Encoder-Decoder", "Encoder-Decoder-Skip", "RefineNet",
"FRRN-A", "FRRN-B", "MobileUNet", "MobileUNet-Skip", "PSPNet", "GCN", "DeepLabV3", "DeepLabV3_plus", "AdapNet", "custom"]

SUPPORTED_FRONTENDS = ["ResNet50", "ResNet101", "ResNet152", "MobileNetV2", "InceptionV4"]

def download_checkpoints(model_name):
subprocess.check_output(["python", "get_pretrained_checkpoints.py", "--model=" + model_name])
subprocess.check_output(["python", "utils/get_pretrained_checkpoints.py", "--model=" + model_name])



def build_model(model_name, net_input, num_classes, frontend="ResNet101", is_training=True):
def build_model(model_name, net_input, num_classes, crop_width, crop_height, frontend="ResNet101", is_training=True):
# Get the selected model.
# Some of them require pre-trained ResNet

Expand Down Expand Up @@ -63,7 +64,7 @@ def build_model(model_name, net_input, num_classes, frontend="ResNet101", is_tra
elif model_name == "PSPNet":
# Image size is required for PSPNet
# PSPNet requires pre-trained ResNet weights
network, init_fn = build_pspnet(net_input, label_size=[args.crop_height, args.crop_width], preset_model = model_name, frontend=frontend, num_classes=num_classes, is_training=is_training)
network, init_fn = build_pspnet(net_input, label_size=[crop_height, crop_width], preset_model = model_name, frontend=frontend, num_classes=num_classes, is_training=is_training)
elif model_name == "GCN":
# GCN requires pre-trained ResNet weights
network, init_fn = build_gcn(net_input, preset_model = model_name, frontend=frontend, num_classes=num_classes, is_training=is_training)
Expand Down
Empty file added frontends/__init__.py
Empty file.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion models/inception_v4.py → frontends/inception_v4.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

import tensorflow as tf

import inception_utils
from frontends import inception_utils

slim = tf.contrib.slim

Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions models/mobilenet_v2.py → frontends/mobilenet_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@

import tensorflow as tf

import conv_blocks as ops
import mobilenet_base as lib
from frontends import conv_blocks as ops
from frontends import mobilenet_base as lib

slim = tf.contrib.slim
op = lib.op
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion models/resnet_v1.py → frontends/resnet_v1.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import tensorflow as tf
from tensorflow.contrib import slim
import resnet_utils
from frontends import resnet_utils

resnet_arg_scope = resnet_utils.resnet_arg_scope

Expand Down
2 changes: 1 addition & 1 deletion models/resnet_v2.py → frontends/resnet_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

import tensorflow as tf

import resnet_utils
from frontends import resnet_utils

slim = tf.contrib.slim
resnet_arg_scope = resnet_utils.resnet_arg_scope
Expand Down
Binary file modified iou_vs_epochs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion models/AdapNet.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import tensorflow as tf
from tensorflow.contrib import slim
import numpy as np
import resnet_v2
from frontends import resnet_v2
import os, sys


Expand Down
2 changes: 1 addition & 1 deletion models/DeepLabV3.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import tensorflow as tf
from tensorflow.contrib import slim
import numpy as np
import frontend_builder
from builders import frontend_builder
import os, sys

def Upsampling(inputs,feature_map_shape):
Expand Down
3 changes: 1 addition & 2 deletions models/DeepLabV3_plus.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

import tensorflow as tf
from tensorflow.contrib import slim
import frontend_builder
from builders import frontend_builder
import numpy as np
import resnet_v2
import os, sys

def Upsampling(inputs,feature_map_shape):
Expand Down
1 change: 0 additions & 1 deletion models/FRRN.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import tensorflow as tf
from tensorflow.contrib import slim
import resnet_v1

def Upsampling(inputs,scale):
return tf.image.resize_nearest_neighbor(inputs, size=[tf.shape(inputs)[1]*scale, tf.shape(inputs)[2]*scale])
Expand Down
2 changes: 1 addition & 1 deletion models/GCN.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import tensorflow as tf
from tensorflow.contrib import slim
import frontend_builder
from builders import frontend_builder
import os, sys

def Upsampling(inputs,scale):
Expand Down
2 changes: 1 addition & 1 deletion models/ICNet.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import tensorflow as tf
from tensorflow.contrib import slim
import numpy as np
import frontend_builder
from frontends import frontend_builder
import os, sys

def Upsampling_by_shape(inputs, feature_map_shape):
Expand Down
2 changes: 1 addition & 1 deletion models/PSPNet.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import tensorflow as tf
from tensorflow.contrib import slim
import numpy as np
import frontend_builder
from builders import frontend_builder
import os, sys

def Upsampling(inputs,feature_map_shape):
Expand Down
4 changes: 2 additions & 2 deletions models/RefineNet.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import tensorflow as tf
from tensorflow.contrib import slim
import frontend_builder
from builders import frontend_builder
import os, sys

def Upsampling(inputs,scale):
Expand Down Expand Up @@ -142,7 +142,7 @@ def RefineBlock(high_inputs=None,low_inputs=None):



def build_refinenet(inputs, num_classes, preset_model='RefineNet', frontend="ResNet101", weight_decay=1e-5, upscaling_method="bilinear", pretrained_dir="models"):
def build_refinenet(inputs, num_classes, preset_model='RefineNet', frontend="ResNet101", weight_decay=1e-5, upscaling_method="bilinear", pretrained_dir="models", is_training=True):
"""
Builds the RefineNet model.
Expand Down
Empty file added models/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion models/custom_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import tensorflow as tf
import tensorflow.contrib.slim as slim
import numpy as np
import frontend_builder
from builders import frontend_builder

def conv_block(inputs, n_filters, filter_size=[3, 3], dropout_p=0.0):
"""
Expand Down
5 changes: 2 additions & 3 deletions predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
import argparse
import numpy as np

import utils
import helpers
import model_builder
from utils import utils, helpers
from builders import model_builder

parser = argparse.ArgumentParser()
parser.add_argument('--image', type=str, default=None, required=True, help='The image you want to predict on. ')
Expand Down
5 changes: 2 additions & 3 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
import argparse
import numpy as np

import utils
import helpers
import model_builder
from utils import utils, helpers
from builders import model_builder

parser = argparse.ArgumentParser()
parser.add_argument('--checkpoint_path', type=str, default=None, required=True, help='The path to the latest checkpoint weights for your model.')
Expand Down
9 changes: 3 additions & 6 deletions train.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@
import subprocess


import helpers
import utils
from utils import utils, helpers
from builders import model_builder

import matplotlib.pyplot as plt

sys.path.append("models")
import model_builder

def str2bool(v):
if v.lower() in ('yes', 'true', 't', 'y', '1'):
return True
Expand Down Expand Up @@ -90,7 +87,7 @@ def data_augmentation(input_image, output_image):
net_input = tf.placeholder(tf.float32,shape=[None,None,None,3])
net_output = tf.placeholder(tf.float32,shape=[None,None,None,num_classes])

network, init_fn = model_builder.build_model(args.model, frontend=args.frontend, net_input=net_input, num_classes=num_classes, is_training=True)
network, init_fn = model_builder.build_model(model_name=args.model, frontend=args.frontend, net_input=net_input, num_classes=num_classes, crop_width=args.crop_width, crop_height=args.crop_height, is_training=True)

loss = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits=network, labels=net_output))

Expand Down
Empty file added utils/__init__.py
Empty file.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion utils.py → utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
recall_score, confusion_matrix, classification_report, \
accuracy_score, f1_score

import helpers
from utils import helpers

def prepare_data(dataset_dir):
train_input_names=[]
Expand Down

0 comments on commit 6e4eb72

Please sign in to comment.