Skip to content

Instantly share code, notes, and snippets.

resnet50 = tf.keras.applications.resnet50
conv_model = resnet50.ResNet50(weights='imagenet', include_top=False, input_shape=(228,228,3))
for layer in conv_model.layers:
layer.trainable = False
x = Conv2D(128, (1, 1), activation = 'relu', name='block6_conv1_table')(conv_model.output)
x = Dropout(0.8, name='block6_dropout_1')(x)
x = Conv2D(128, (1, 1), activation = 'relu', name='block6_conv2_table')(x)
x = Dropout(0.8, name='block6_dropout_2')(x)
def create_mask(pred_mask1, pred_mask2):
"""Reference - https://github.com/jainammm/TableNet/blob/master/TableNet.ipynb
"""
pred_mask1 = tf.argmax(pred_mask1, axis=-1)
pred_mask1 = pred_mask1[..., tf.newaxis]
pred_mask2 = tf.argmax(pred_mask2, axis=-1)
pred_mask2 = pred_mask2[..., tf.newaxis]
return pred_mask1[0], pred_mask2[0]
def get_file_size(file_path):
size = os.path.getsize(file_path)
return size
def convert_bytes(size, unit=None):
if unit == "KB":
return print('File size: ' + str(round(size / 1024, 3)) + ' Kilobytes')
elif unit == "MB":
return print('File size: ' + str(round(size / (1024 * 1024), 3)) + ' Megabytes')
else:
tf_lite_converter = tf.lite.TFLiteConverter.from_keras_model(model)
tf_lite_converter.optimizations = [tf.lite.Optimize.OPTIMIZE_FOR_SIZE]
tflite_model = tf_lite_converter.convert()
# Reference - https://github.com/jainammm/TableNet/blob/master/TableNet.ipynb
class TableNet:
@staticmethod
def build_table_decoder(inputs, pool3, pool4):
x = Conv2D(512, (1, 1), activation = 'relu', name='conv7_table')(inputs)
x = UpSampling2D(size=(2, 2))(x)
concatenated = Concatenate()([x, pool4])
# concatenated = concatenate([x, pool4])