本文整理汇总了Python中utils.combine_images方法的典型用法代码示例。如果您正苦于以下问题:Python utils.combine_images方法的具体用法?Python utils.combine_images怎么用?Python utils.combine_images使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utils
的用法示例。
在下文中一共展示了utils.combine_images方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test
# 需要导入模块: import utils [as 别名]
# 或者: from utils import combine_images [as 别名]
def test(model, data, args):
x_test, y_test = data
print('Testing the model...')
y_pred, y_pred0, y_pred1, y_pred2, y_pred3, x_recon = model.predict(x_test, batch_size=100)
print('Test Accuracy (All DigitCaps): ', 100.0*np.sum(np.argmax(y_pred, 1) == np.argmax(y_test, 1))/(1.0*y_test.shape[0]))
print('Test Accuracy (Merged DigitCaps): ', 100.0*np.sum(np.argmax(y_pred0, 1) == np.argmax(y_test, 1))/(1.0*y_test.shape[0]))
print('Test Accuracy (Level 1 DigitCaps): ', 100.0*np.sum(np.argmax(y_pred1, 1) == np.argmax(y_test, 1))/(1.0*y_test.shape[0]))
print('Test Accuracy (Level 2 DigitCaps): ', 100.0*np.sum(np.argmax(y_pred2, 1) == np.argmax(y_test, 1))/(1.0*y_test.shape[0]))
print('Test Accuracy (Level 3 DigitCaps): ', 100.0*np.sum(np.argmax(y_pred3, 1) == np.argmax(y_test, 1))/(1.0*y_test.shape[0]))
img = combine_images(np.concatenate([x_test[:50],x_recon[:50]]))
image = img * 255
Image.fromarray(image.astype(np.uint8)).save(args.save_dir + "/real_and_recon.png")
print()
print('Reconstructed images are saved to %s/real_and_recon.png' % args.save_dir)
plt.imshow(plt.imread(args.save_dir + "/real_and_recon.png"))
plt.show()
示例2: test
# 需要导入模块: import utils [as 别名]
# 或者: from utils import combine_images [as 别名]
def test(model, data):
x_test, y_test = data
y_pred, x_recon = model.predict(x_test, batch_size=100)
print('-'*50)
print('Test acc:', np.sum(np.argmax(y_pred, 1) == np.argmax(y_test, 1))/y_test.shape[0])
import matplotlib.pyplot as plt
from utils import combine_images
from PIL import Image
img = combine_images(np.concatenate([x_test[:50],x_recon[:50]]))
image = img * 255
Image.fromarray(image.astype(np.uint8)).save("real_and_recon.png")
print()
print('Reconstructed images are saved to ./real_and_recon.png')
print('-'*50)
plt.imshow(plt.imread("real_and_recon.png", ))
plt.show()
示例3: manipulate_latent
# 需要导入模块: import utils [as 别名]
# 或者: from utils import combine_images [as 别名]
def manipulate_latent(model, data, args):
print('-'*30 + 'Begin: manipulate' + '-'*30)
x_test, y_test = data
index = np.argmax(y_test, 1) == args.digit
number = np.random.randint(low=0, high=sum(index) - 1)
x, y = x_test[index][number], y_test[index][number]
x, y = np.expand_dims(x, 0), np.expand_dims(y, 0)
noise = np.zeros([1, 10, 16])
x_recons = []
for dim in range(16):
for r in [-0.25, -0.2, -0.15, -0.1, -0.05, 0, 0.05, 0.1, 0.15, 0.2, 0.25]:
tmp = np.copy(noise)
tmp[:,:,dim] = r
x_recon = model.predict([x, y, tmp])
x_recons.append(x_recon)
x_recons = np.concatenate(x_recons)
img = combine_images(x_recons, height=16)
image = img*255
Image.fromarray(image.astype(np.uint8)).save(args.save_dir + '/manipulate-%d.png' % args.digit)
print('manipulated result saved to %s/manipulate-%d.png' % (args.save_dir, args.digit))
print('-' * 30 + 'End: manipulate' + '-' * 30)
示例4: show_reconstruction
# 需要导入模块: import utils [as 别名]
# 或者: from utils import combine_images [as 别名]
def show_reconstruction(model, test_loader, n_images, args):
import matplotlib.pyplot as plt
from utils import combine_images
from PIL import Image
import numpy as np
model.eval()
for x, _ in test_loader:
x = Variable(x[:min(n_images, x.size(0))].cuda(), volatile=True)
_, x_recon = model(x)
data = np.concatenate([x.data, x_recon.data])
img = combine_images(np.transpose(data, [0, 2, 3, 1]))
image = img * 255
Image.fromarray(image.astype(np.uint8)).save(args.save_dir + "/real_and_recon.png")
print()
print('Reconstructed images are saved to %s/real_and_recon.png' % args.save_dir)
print('-' * 70)
plt.imshow(plt.imread(args.save_dir + "/real_and_recon.png", ))
plt.show()
break
示例5: test
# 需要导入模块: import utils [as 别名]
# 或者: from utils import combine_images [as 别名]
def test(model, data, args):
x_test, y_test = data
print('Testing the model...')
y_pred, x_recon = model.predict(x_test, batch_size=100)
print('Test Accuracy: ', 100.0*np.sum(np.argmax(y_pred, 1) == np.argmax(y_test, 1))/(1.0*y_test.shape[0]))
img = combine_images(np.concatenate([x_test[:50],x_recon[:50]]))
image = img * 255
Image.fromarray(image.astype(np.uint8)).save(args.save_dir + "/real_and_recon.png")
print()
print('Reconstructed images are saved to %s/real_and_recon.png' % args.save_dir)
plt.imshow(plt.imread(args.save_dir + "/real_and_recon.png"))
plt.show()
示例6: save_output_image
# 需要导入模块: import utils [as 别名]
# 或者: from utils import combine_images [as 别名]
def save_output_image(self,samples,image_name):
"""
Visualizing and saving images in the .png format
:param samples: images to be visualized
:param image_name: name of the saved .png file
"""
if not os.path.exists(args.save_dir+"/images"):
os.makedirs(args.save_dir+"/images")
img = combine_images(samples)
img = img * 255
Image.fromarray(img.astype(np.uint8)).save(args.save_dir + "/images/"+image_name+".png")
print(image_name, "Image saved.")
示例7: test
# 需要导入模块: import utils [as 别名]
# 或者: from utils import combine_images [as 别名]
def test(model, data, args):
x_test, y_test = data
y_pred, x_recon = model.predict(x_test, batch_size=100)
print('-'*30 + 'Begin: test' + '-'*30)
print('Test acc:', np.sum(np.argmax(y_pred, 1) == np.argmax(y_test, 1))/y_test.shape[0])
img = combine_images(np.concatenate([x_test[:50],x_recon[:50]]))
image = img * 255
Image.fromarray(image.astype(np.uint8)).save(args.save_dir + "/real_and_recon.png")
print()
print('Reconstructed images are saved to %s/real_and_recon.png' % args.save_dir)
print('-' * 30 + 'End: test' + '-' * 30)
plt.imshow(plt.imread(args.save_dir + "/real_and_recon.png"))
plt.show()