use gray color map
This commit is contained in:
@@ -10,7 +10,7 @@ if __name__ == "__main__":
|
|||||||
prj_root = "/home/jens/work/repos/Rbm"
|
prj_root = "/home/jens/work/repos/Rbm"
|
||||||
|
|
||||||
# Create Labeler
|
# Create Labeler
|
||||||
enc = Label(voc_size, 16, work_dir)
|
enc = Label(voc_size, 16, Label.EncodingType.OneHot, work_dir)
|
||||||
|
|
||||||
# Load
|
# Load
|
||||||
enc.fitter.load()
|
enc.fitter.load()
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
from rbm.model import Model
|
from rbm.model import Model
|
||||||
from rbm.entity import Entity, EntityParams, TrainingParams
|
from rbm.entity import Entity, EntityParams, TrainingParams
|
||||||
from rbm.matrix import Mat, np, read_armadillo
|
from rbm.matrix import Mat, np, read_armadillo
|
||||||
@@ -10,7 +9,7 @@ from rbm.label import Label
|
|||||||
class TestModel(Model):
|
class TestModel(Model):
|
||||||
def __init__(self, name: str, work_dir: str = '.'):
|
def __init__(self, name: str, work_dir: str = '.'):
|
||||||
super().__init__(name, work_dir)
|
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_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))
|
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
|
# Train
|
||||||
# Create Labeler
|
# Create Labeler
|
||||||
enc = Label(20, 16, work_dir)
|
enc = Label(20, 16, Label.EncodingType.OneHot, work_dir)
|
||||||
|
|
||||||
# Load
|
# Load
|
||||||
enc.fitter.load()
|
enc.fitter.load()
|
||||||
@@ -71,19 +70,20 @@ if __name__ == "__main__":
|
|||||||
# save state
|
# save state
|
||||||
model.save()
|
model.save()
|
||||||
|
|
||||||
fig, axes = plt.subplots(3, len(test_batch), figsize=(12, 3))
|
cmap = 'Grays'
|
||||||
for index, image in enumerate(test_batch):
|
fig, axes = plt.subplots(3, len(train_batch), figsize=(12, 3))
|
||||||
|
for index, image in enumerate(train_batch):
|
||||||
label_zero = np.zeros(shape=16)
|
label_zero = np.zeros(shape=16)
|
||||||
image_zero = np.zeros(shape=96*96)
|
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, label_zero))
|
||||||
# image_reconst, labels_reconst = model.reconstruct(model.forward2(image_zero, encoded[index, :]))
|
# 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))
|
img = np.reshape(img, (96, 96))
|
||||||
axes[0][index].imshow(img)
|
axes[0][index].imshow(img, cmap=cmap)
|
||||||
axes[0][index].axis('off')
|
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[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')
|
axes[2][index].axis('off')
|
||||||
|
|
||||||
plt.show()
|
plt.show()
|
||||||
|
|||||||
Reference in New Issue
Block a user