本文整理汇总了Python中rbm.RBM.regenerate方法的典型用法代码示例。如果您正苦于以下问题:Python RBM.regenerate方法的具体用法?Python RBM.regenerate怎么用?Python RBM.regenerate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rbm.RBM
的用法示例。
在下文中一共展示了RBM.regenerate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from rbm import RBM [as 别名]
# 或者: from rbm.RBM import regenerate [as 别名]
class SFG:
def __init__(self):
self.image_width = self.image_height = 28
self.visible_units = self.image_width * self.image_height
self.hidden_units = self.visible_units / 10
self.rbm = RBM(self.visible_units, self.hidden_units)
#assumes there are only training images in the training_folder
def train(self, training_folder, epochs = 500):
data = []
for training_image in os.listdir(training_folder):
image = pil.open(training_folder + '/' + training_image)
image = self.array_for_image(image)
data.append(image)
self.rbm.train(data, epochs)
#takes a pil Image and returns an arary of 1s and 0s
def array_for_image(self, image):
return np.array(image.convert("L")).flatten() / 255
def regen_image(self, image, samples):
data = self.array_for_image(image)
(v, _) = self.rbm.regenerate([data],samples)
return self.image_for_array(v[0])
def image_for_array(self, array):
img_array = []
for row in range(0, self.image_height):
img_array.append(array[row * self.image_width : (row+1) * self.image_width])
img_array = np.asarray(img_array, np.uint8) * 255
return pil.fromarray(img_array)
示例2: RBMTest
# 需要导入模块: from rbm import RBM [as 别名]
# 或者: from rbm.RBM import regenerate [as 别名]
class RBMTest(unittest.TestCase):
def setUp(self):
self.rbm = RBM(10,10)
def can_make_rbm_test(self):
rbm = RBM(10, 10)
def logistic_function_test(self):
self.assertEquals(self.rbm.logistic(0), 1)
def train_throws_error_with_inconsistent_matrix_sizes_test(self):
with self.assertRaises(TypeError):
self.rbm.train([[1,0,1,1,1,1,0,1], [1,1,1,1,0], [1,1,1,1,1,1]])
def regenerate_throws_error_with_inconsistent_matrix_sizes_test(self):
with self.assertRaises(TypeError):
self.rbm.regenerate([[1,0,1,1,1,1,0,1], [1,1,1,1,0], [1,1,1,1,1,1]])