Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test #95

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

test #95

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion keras_frcnn/RoiPoolingConv.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class RoiPoolingConv(Layer):
'''
def __init__(self, pool_size, num_rois, **kwargs):

self.dim_ordering = K.common.image_dim_ordering()
self.dim_ordering = K.image_data_format()
assert self.dim_ordering in {'tf', 'th'}, 'dim_ordering must be in {tf, th}'

self.pool_size = pool_size
Expand Down
6 changes: 3 additions & 3 deletions keras_frcnn/losses.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from keras import backend as K
from keras.objectives import categorical_crossentropy

if K.common.image_dim_ordering() == 'tf':
if K.image_data_format() == 'tf':
import tensorflow as tf

lambda_rpn_regr = 1.0
Expand All @@ -15,7 +15,7 @@

def rpn_loss_regr(num_anchors):
def rpn_loss_regr_fixed_num(y_true, y_pred):
if K.common.image_dim_ordering() == 'th':
if K.image_data_format() == 'th':
x = y_true[:, 4 * num_anchors:, :, :] - y_pred
x_abs = K.abs(x)
x_bool = K.less_equal(x_abs, 1.0)
Expand All @@ -34,7 +34,7 @@ def rpn_loss_regr_fixed_num(y_true, y_pred):

def rpn_loss_cls(num_anchors):
def rpn_loss_cls_fixed_num(y_true, y_pred):
if K.common.image_dim_ordering() == 'tf':
if K.image_data_format() == 'tf':
return lambda_rpn_class * K.sum(y_true[:, :, :, :num_anchors] * K.binary_crossentropy(y_pred[:, :, :, :], y_true[:, :, :, num_anchors:])) / K.sum(epsilon + y_true[:, :, :, :num_anchors])
else:
return lambda_rpn_class * K.sum(y_true[:, :num_anchors, :, :] * K.binary_crossentropy(y_pred[:, :, :, :], y_true[:, num_anchors:, :, :])) / K.sum(epsilon + y_true[:, :num_anchors, :, :])
Expand Down
14 changes: 7 additions & 7 deletions keras_frcnn/resnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from keras_frcnn.FixedBatchNormalization import FixedBatchNormalization

def get_weight_path():
if K.common.image_dim_ordering() == 'th':
if K.image_data_format() == 'th':
return 'resnet50_weights_th_dim_ordering_th_kernels_notop.h5'
else:
return 'resnet50_weights_tf_dim_ordering_tf_kernels.h5'
Expand All @@ -39,7 +39,7 @@ def identity_block(input_tensor, kernel_size, filters, stage, block, trainable=T

nb_filter1, nb_filter2, nb_filter3 = filters

if K.common.image_dim_ordering() == 'tf':
if K.image_data_format() == 'tf':
bn_axis = 3
else:
bn_axis = 1
Expand Down Expand Up @@ -68,7 +68,7 @@ def identity_block_td(input_tensor, kernel_size, filters, stage, block, trainabl
# identity block time distributed

nb_filter1, nb_filter2, nb_filter3 = filters
if K.common.image_dim_ordering() == 'tf':
if K.image_data_format() == 'tf':
bn_axis = 3
else:
bn_axis = 1
Expand All @@ -95,7 +95,7 @@ def identity_block_td(input_tensor, kernel_size, filters, stage, block, trainabl
def conv_block(input_tensor, kernel_size, filters, stage, block, strides=(2, 2), trainable=True):

nb_filter1, nb_filter2, nb_filter3 = filters
if K.common.image_dim_ordering() == 'tf':
if K.image_data_format() == 'tf':
bn_axis = 3
else:
bn_axis = 1
Expand Down Expand Up @@ -127,7 +127,7 @@ def conv_block_td(input_tensor, kernel_size, filters, stage, block, input_shape,
# conv block time distributed

nb_filter1, nb_filter2, nb_filter3 = filters
if K.common.image_dim_ordering() == 'tf':
if K.image_data_format() == 'tf':
bn_axis = 3
else:
bn_axis = 1
Expand Down Expand Up @@ -156,7 +156,7 @@ def conv_block_td(input_tensor, kernel_size, filters, stage, block, input_shape,
def nn_base(input_tensor=None, trainable=False):

# Determine proper input shape
if K.common.image_dim_ordering() == 'th':
if K.image_data_format() == 'th':
input_shape = (3, None, None)
else:
input_shape = (None, None, 3)
Expand All @@ -169,7 +169,7 @@ def nn_base(input_tensor=None, trainable=False):
else:
img_input = input_tensor

if K.common.image_dim_ordering() == 'tf':
if K.image_data_format() == 'tf':
bn_axis = 3
else:
bn_axis = 1
Expand Down
6 changes: 3 additions & 3 deletions keras_frcnn/vgg.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@


def get_weight_path():
if K.common.image_dim_ordering() == 'th':
if K.image_data_format() == 'th':
print('pretrained weights not available for VGG with theano backend')
return
else:
Expand All @@ -37,7 +37,7 @@ def nn_base(input_tensor=None, trainable=False):


# Determine proper input shape
if K.common.image_dim_ordering() == 'th':
if K.image_data_format() == 'th':
input_shape = (3, None, None)
else:
input_shape = (None, None, 3)
Expand All @@ -50,7 +50,7 @@ def nn_base(input_tensor=None, trainable=False):
else:
img_input = input_tensor

if K.common.image_dim_ordering() == 'tf':
if K.image_data_format() == 'tf':
bn_axis = 3
else:
bn_axis = 1
Expand Down
15 changes: 8 additions & 7 deletions train_frcnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,14 @@
# set the path to weights based on backend and model
C.base_net_weights = nn.get_weight_path()

train_imgs, classes_count, class_mapping = get_data(options.train_path, 'trainval')
val_imgs, _, _ = get_data(options.train_path, 'test')
train_imgs, classes_count, class_mapping = get_data(options.train_path)
val_imgs, _, _ = get_data(options.train_path)

'''
if 'bg' not in classes_count:
classes_count['bg'] = 0
class_mapping['bg'] = len(class_mapping)

'''
C.class_mapping = class_mapping

inv_map = {v: k for k, v in class_mapping.items()}
Expand All @@ -109,14 +110,14 @@
#train_imgs = [s for s in all_imgs if s['imageset'] == 'trainval']
#val_imgs = [s for s in all_imgs if s['imageset'] == 'test']

print(f'Num train samples {len(train_imgs}')
print(f'Num train samples {len(train_imgs)}')
print(f'Num val samples {len(val_imgs)}')


data_gen_train = data_generators.get_anchor_gt(train_imgs, classes_count, C, nn.get_img_output_length, K.common.image_dim_ordering(), mode='train')
data_gen_val = data_generators.get_anchor_gt(val_imgs, classes_count, C, nn.get_img_output_length,K.common.image_dim_ordering(), mode='val')
data_gen_train = data_generators.get_anchor_gt(train_imgs, classes_count, C, nn.get_img_output_length, K.image_data_format(), mode='train')
data_gen_val = data_generators.get_anchor_gt(val_imgs, classes_count, C, nn.get_img_output_length,K.image_data_format(), mode='val')

if K.common.image_dim_ordering() == 'th':
if K.image_data_format() == 'th':
input_shape_img = (3, None, None)
else:
input_shape_img = (None, None, 3)
Expand Down