def __init__(self, in_shape, n_rotations, preprocess, lite=False): self.n_rotations = n_rotations self.preprocess = preprocess max_dim = np.max(in_shape[:2]) self.padding = np.zeros((3, 2), dtype=int) pad = (max_dim - np.array(in_shape[:2])) / 2 self.padding[:2] = pad.reshape(2, 1) in_shape = np.array(in_shape) in_shape += np.sum(self.padding, axis=1) in_shape = tuple(in_shape) # Initialize fully convolutional Residual Network with 43 layers and # 8-stride (3 2x2 max pools and 3 2x bilinear upsampling) if lite: d_in, d_out = ResNet36_4s(in_shape, 1) else: d_in, d_out = ResNet43_8s(in_shape, 1) self.model = tf.keras.models.Model(inputs=[d_in], outputs=[d_out]) self.optim = tf.keras.optimizers.Adam(learning_rate=1e-4) # self.optim = tf.keras.optimizers.SGD(learning_rate=1e-3, momentum=0.9, nesterov=True, name='SGD') self.metric = tf.keras.metrics.Mean(name='loss_attention')
def __init__(self, input_shape, descriptor_dim, num_rotations, preprocess, lite=False): self.preprocess = preprocess self.num_rotations = num_rotations self.descriptor_dim = descriptor_dim max_dim = np.max(input_shape[:2]) self.padding = np.zeros((3, 2), dtype=int) pad = (max_dim - np.array(input_shape[:2])) / 2 self.padding[:2] = pad.reshape(2, 1) input_shape = np.array(input_shape) input_shape += np.sum(self.padding, axis=1) input_shape = tuple(input_shape) # Initialize fully convolutional Residual Network with 43 layers and # 8-stride (3 2x2 max pools and 3 2x bilinear upsampling) if lite: d_in, d_out = ResNet36_4s(input_shape, self.descriptor_dim) else: d_in, d_out = ResNet43_8s(input_shape, self.descriptor_dim) self.model = tf.keras.models.Model(inputs=[d_in], outputs=[d_out]) self.optim = tf.keras.optimizers.Adam(learning_rate=1e-5) self.metric = tf.keras.metrics.Mean(name='attention_loss')