Skip to content

Instantly share code, notes, and snippets.

View doleron's full-sized avatar
💭
I may be slow to respond.

Luiz doleron doleron

💭
I may be slow to respond.
View GitHub Profile
@doleron
doleron / ECLiPSe_prolog_install.md
Last active May 8, 2024 16:46
Installation of ECLiPSe prolog interpreter

This instructions are intended to run on any linux debian, using Ubuntu 20.04 here.

The ECLiPSe prolog website is https://eclipseclp.org/index.html

Disclaimer: ECLiPSe prolog is not Eclipse IDE !

pre flight

as usual, update the machine

plt.figure(figsize=(20, 10))
for images, labels in train_ds.take(1):
for i in range(BATCH_SIZE):
ax = plt.subplot(4, BATCH_SIZE//4, i + 1)
label = labels[0][i]
box = (labels[1][i] * input_size)
box = tf.cast(box, tf.int32)
image = images[i].numpy().astype("float") * 255.0
image = image.astype(np.uint8)
VALIDATION_BATCH_SIZE = 2
def build_validation_dataset():
pairs_tensor = tf.convert_to_tensor(validation_pairs)
labels_tensor = tf.convert_to_tensor(validation_pairs_labels)
result = tf.data.Dataset.from_tensor_slices((pairs_tensor, labels_tensor))
result = result.map(lambda pair, label: (load_images(pair), label))
class RandomInvert(tf.keras.layers.Layer):
def __init__(self, max_value = 255, factor=0.5, **kwargs):
super().__init__(**kwargs)
self.factor = factor
self.max_value = max_value
def call(self, x):
if tf.random.uniform([]) < self.factor:
x = (self.max_value - x)
return x
EPOCHS = 200
model.compile(loss=contrastive_loss_with_margin(margin=1), optimizer=tf.keras.optimizers.RMSprop(),
metrics=[Custom_Accuracy(), Custom_Precision(), Custom_Recall()])
early_stop = tf.keras.callbacks.EarlyStopping(monitor='val_loss', patience = 30, start_from_epoch = 10)
checkpoint = tf.keras.callbacks.ModelCheckpoint(model_file, monitor="val_loss", mode="min", save_best_only=True, verbose=1)
history = model.fit(train_ds,
early_stop = tf.keras.callbacks.EarlyStopping(monitor='val_loss', patience = 10)
history = model.fit(train_ds, validation_data=validation_ds, epochs=EPOCHS, callbacks=[early_stop])
def checking_wrong_predictions():
for images, labels in validation_ds:
predictions = model.predict(images, verbose = 0)
for i in range(VALIDATION_BATCH_SIZE):
img_A = (images[0][i].numpy()*255).astype("uint8")
img_B = (images[1][i].numpy()*255).astype("uint8")
import numpy as np
y_pred_test = model.predict(validation_ds)
y_pred_int = tf.cast(tf.math.less(y_pred_test, 0.5), tf.int32)
y_true = np.concatenate([y for x, y in validation_ds], axis=0)
tf.math.confusion_matrix(y_true, y_pred_int)
metrics = model.evaluate(validation_ds)
test_loss = metrics[0]
test_accuracy = metrics[1]
test_precision = metrics[2]
test_recall = metrics[3]
print("Test Loss = {:.4f}, Test Accuracy = {:.4f}, Test Precision = {:.4f}, Test Recall = {:.4f}"
.format(test_loss, test_accuracy, test_precision, test_recall))
model.compile(loss=contrastive_loss_with_margin(margin=1), optimizer=tf.keras.optimizers.RMSprop(),
metrics=[Custom_Accuracy(), Custom_Precision(), Custom_Recall()])