Пример #1
0

def loss_function_2(y_true, y_pred):
    """ Positional output loss """
    square_diff = tf.math.squared_difference(y_true, y_pred)
    mask = tf.not_equal(y_true, 0)
    mask = tf.cast(mask, tf.float32)
    square_diff = tf.multiply(square_diff, mask)
    square_diff = tf.reduce_mean(square_diff, 1)
    square_diff = tf.reduce_mean(square_diff, 0)
    loss = tf.reduce_mean(square_diff)
    return loss


# Creating the model
model = model()
model.summary()

# Compile
adam = Adam(lr=1e-5, beta_1=0.9, beta_2=0.999, epsilon=1e-10, decay=0.0)
loss_function = {"prob_output": loss_function_1, "pos_output": loss_function_2}
model.compile(optimizer=adam, loss=loss_function, metrics=None)

# Train
epochs = 10
batch_size = 256
train_set_size = 25090
valid_set_size = 1317
training_steps_per_epoch = ceil(train_set_size / batch_size)
validation_steps_per_epoch = ceil(valid_set_size / batch_size)
Пример #2
0
 def __init__(self, weights):
     self.model = model()
     self.model.load_weights(weights)