use gray color map

This commit is contained in:
2026-01-02 22:50:03 +01:00
parent 082bb3c566
commit fa9f595be6
2 changed files with 10 additions and 10 deletions
+9 -9
View File
@@ -1,6 +1,5 @@
import os
import matplotlib.pyplot as plt
from rbm.model import Model
from rbm.entity import Entity, EntityParams, TrainingParams
from rbm.matrix import Mat, np, read_armadillo
@@ -10,7 +9,7 @@ from rbm.label import Label
class TestModel(Model):
def __init__(self, name: str, work_dir: str = '.'):
super().__init__(name, work_dir)
# self.unit_image = Entity((96*96, 16), EntityParams(do_gaussian_visible=True, do_gaussian_hidden=False), TrainingParams(learning_rate=0.00001, momentum=0.9, do_rao_blackwell=True, num_epochs=1000))
# self.unit_image = Entity((96*96, 16), EntityParams(do_gaussian_visible=True, do_gaussian_hidden=False, num_gibbs_samples=3), TrainingParams(learning_rate=0.00001, momentum=0.9, do_rao_blackwell=False, num_epochs=1000))
self.unit_image = Entity((96 * 96, 16), EntityParams(do_gaussian_visible=True, do_gaussian_hidden=False))
self.unit_combine = Entity((32, 64), EntityParams(), TrainingParams(learning_rate=0.01, momentum=0.9, do_rao_blackwell=True, num_epochs=1000))
@@ -55,7 +54,7 @@ if __name__ == "__main__":
# Train
# Create Labeler
enc = Label(20, 16, work_dir)
enc = Label(20, 16, Label.EncodingType.OneHot, work_dir)
# Load
enc.fitter.load()
@@ -71,19 +70,20 @@ if __name__ == "__main__":
# save state
model.save()
fig, axes = plt.subplots(3, len(test_batch), figsize=(12, 3))
for index, image in enumerate(test_batch):
cmap = 'Grays'
fig, axes = plt.subplots(3, len(train_batch), figsize=(12, 3))
for index, image in enumerate(train_batch):
label_zero = np.zeros(shape=16)
image_zero = np.zeros(shape=96*96)
image_reconst, labels_reconst = model.reconstruct(model.forward2(image, label_zero))
# image_reconst, labels_reconst = model.reconstruct(model.forward2(image_zero, encoded[index, :]))
img = 2*(image_reconst + 0.5)
img = 1-2*(image_reconst + 0.5)
img = np.reshape(img, (96, 96))
axes[0][index].imshow(img)
axes[0][index].imshow(img, cmap=cmap)
axes[0][index].axis('off')
axes[1][index].imshow(np.reshape(labels_reconst, (4,4)))
axes[1][index].imshow(np.reshape(labels_reconst, (4,4)), cmap=cmap)
axes[1][index].axis('off')
axes[2][index].imshow(np.reshape(encoded[index, :], (4,4)))
axes[2][index].imshow(np.reshape(encoded[index, :], (4,4)), cmap=cmap)
axes[2][index].axis('off')
plt.show()