From 1d7363bd4dccdf496cb5645a2f4fc7180aa7f6e6 Mon Sep 17 00:00:00 2001 From: vijayml457 <71607088+vijayml457@users.noreply.github.com> Date: Mon, 21 Sep 2020 00:42:17 +0530 Subject: [PATCH 01/10] Update train_frcnn.py --- train_frcnn.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/train_frcnn.py b/train_frcnn.py index ee5b4990..dffa7d26 100644 --- a/train_frcnn.py +++ b/train_frcnn.py @@ -109,7 +109,7 @@ #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)}') From b8afb6f6903310c01ba17717a0eb6846a06bf460 Mon Sep 17 00:00:00 2001 From: vijayml457 <71607088+vijayml457@users.noreply.github.com> Date: Mon, 21 Sep 2020 00:46:50 +0530 Subject: [PATCH 02/10] Update train_frcnn.py --- train_frcnn.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/train_frcnn.py b/train_frcnn.py index dffa7d26..7ba0d799 100644 --- a/train_frcnn.py +++ b/train_frcnn.py @@ -113,10 +113,10 @@ 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_dim_ordering(), mode='train') +data_gen_val = data_generators.get_anchor_gt(val_imgs, classes_count, C, nn.get_img_output_length,K.image_dim_ordering(), mode='val') -if K.common.image_dim_ordering() == 'th': +if K.image_dim_ordering() == 'th': input_shape_img = (3, None, None) else: input_shape_img = (None, None, 3) From ad28a366e2ce1a5c9fed125d5a41179f4a1b33d8 Mon Sep 17 00:00:00 2001 From: vijayml457 <71607088+vijayml457@users.noreply.github.com> Date: Mon, 21 Sep 2020 00:49:32 +0530 Subject: [PATCH 03/10] Update losses.py --- keras_frcnn/losses.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/keras_frcnn/losses.py b/keras_frcnn/losses.py index 2bff9675..18d12709 100644 --- a/keras_frcnn/losses.py +++ b/keras_frcnn/losses.py @@ -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_dim_ordering() == 'tf': import tensorflow as tf lambda_rpn_regr = 1.0 @@ -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_dim_ordering() == 'th': x = y_true[:, 4 * num_anchors:, :, :] - y_pred x_abs = K.abs(x) x_bool = K.less_equal(x_abs, 1.0) @@ -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_dim_ordering() == '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, :, :]) From 61a1a930ec0ccf3f2fe10d9f8e2478f4f7244bf3 Mon Sep 17 00:00:00 2001 From: vijayml457 <71607088+vijayml457@users.noreply.github.com> Date: Mon, 21 Sep 2020 00:52:02 +0530 Subject: [PATCH 04/10] Update losses.py --- keras_frcnn/losses.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/keras_frcnn/losses.py b/keras_frcnn/losses.py index 18d12709..ebda41e8 100644 --- a/keras_frcnn/losses.py +++ b/keras_frcnn/losses.py @@ -1,7 +1,7 @@ from keras import backend as K from keras.objectives import categorical_crossentropy -if K.image_dim_ordering() == 'tf': +if K.image_data_format() == 'tf': import tensorflow as tf lambda_rpn_regr = 1.0 @@ -15,7 +15,7 @@ def rpn_loss_regr(num_anchors): def rpn_loss_regr_fixed_num(y_true, y_pred): - if K.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) @@ -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.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, :, :]) From c848ad0efab8c4b2d3fe1dee5136695dbbfae012 Mon Sep 17 00:00:00 2001 From: vijayml457 <71607088+vijayml457@users.noreply.github.com> Date: Mon, 21 Sep 2020 00:52:52 +0530 Subject: [PATCH 05/10] Update train_frcnn.py --- train_frcnn.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/train_frcnn.py b/train_frcnn.py index 7ba0d799..beaa2359 100644 --- a/train_frcnn.py +++ b/train_frcnn.py @@ -113,10 +113,10 @@ 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.image_dim_ordering(), mode='train') -data_gen_val = data_generators.get_anchor_gt(val_imgs, classes_count, C, nn.get_img_output_length,K.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.image_dim_ordering() == 'th': +if K.image_data_format() == 'th': input_shape_img = (3, None, None) else: input_shape_img = (None, None, 3) From cd056fd9982d8ee0ba67f5f463ffa6db90bceba5 Mon Sep 17 00:00:00 2001 From: vijayml457 <71607088+vijayml457@users.noreply.github.com> Date: Mon, 21 Sep 2020 00:55:58 +0530 Subject: [PATCH 06/10] Update resnet.py --- keras_frcnn/resnet.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/keras_frcnn/resnet.py b/keras_frcnn/resnet.py index 147dadc0..f91aedf9 100644 --- a/keras_frcnn/resnet.py +++ b/keras_frcnn/resnet.py @@ -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' @@ -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 @@ -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 @@ -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 @@ -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 @@ -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) @@ -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 From c2e75b00f75fd19dd16c8fb7aba927a0d3361ad5 Mon Sep 17 00:00:00 2001 From: vijayml457 <71607088+vijayml457@users.noreply.github.com> Date: Mon, 21 Sep 2020 01:01:47 +0530 Subject: [PATCH 07/10] Update train_frcnn.py --- train_frcnn.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/train_frcnn.py b/train_frcnn.py index beaa2359..0af3f99d 100644 --- a/train_frcnn.py +++ b/train_frcnn.py @@ -81,8 +81,8 @@ # 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 From 278b1be23afedfd4d6d41ab39327acdba60d3ad0 Mon Sep 17 00:00:00 2001 From: vijayml457 <71607088+vijayml457@users.noreply.github.com> Date: Mon, 21 Sep 2020 01:29:54 +0530 Subject: [PATCH 08/10] Update train_frcnn.py --- train_frcnn.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/train_frcnn.py b/train_frcnn.py index 0af3f99d..120ea6e0 100644 --- a/train_frcnn.py +++ b/train_frcnn.py @@ -84,10 +84,11 @@ 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()} From a4e6b25f9e73302d7cfd25cd15c35df182331d98 Mon Sep 17 00:00:00 2001 From: vijayml457 <71607088+vijayml457@users.noreply.github.com> Date: Mon, 21 Sep 2020 01:40:35 +0530 Subject: [PATCH 09/10] Update vgg.py --- keras_frcnn/vgg.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/keras_frcnn/vgg.py b/keras_frcnn/vgg.py index ce8bc7ca..f0fc8a8e 100644 --- a/keras_frcnn/vgg.py +++ b/keras_frcnn/vgg.py @@ -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: @@ -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) @@ -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 From 3fd3f422f04938b638e0572a09fd0ac98798836d Mon Sep 17 00:00:00 2001 From: vijayml457 <71607088+vijayml457@users.noreply.github.com> Date: Mon, 21 Sep 2020 01:44:54 +0530 Subject: [PATCH 10/10] Update RoiPoolingConv.py --- keras_frcnn/RoiPoolingConv.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/keras_frcnn/RoiPoolingConv.py b/keras_frcnn/RoiPoolingConv.py index ddd86086..63baf57d 100644 --- a/keras_frcnn/RoiPoolingConv.py +++ b/keras_frcnn/RoiPoolingConv.py @@ -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