Python utils.combine_images() Examples
The following are 7
code examples of utils.combine_images().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
utils
, or try the search function
.
Example #1
Source File: 3leveldcnet.py From Multi-level-DCNet with GNU General Public License v3.0 | 6 votes |
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()
Example #2
Source File: capsulenet.py From CapsNet-Fashion-MNIST with MIT License | 6 votes |
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()
Example #3
Source File: capsulenet.py From CapsNet-Keras with MIT License | 6 votes |
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)
Example #4
Source File: capsulenet.py From CapsNet-Pytorch with MIT License | 6 votes |
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
Example #5
Source File: dcnet.py From Multi-level-DCNet with GNU General Public License v3.0 | 5 votes |
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()
Example #6
Source File: textcaps_emnist_bal.py From textcaps with MIT License | 5 votes |
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.")
Example #7
Source File: capsulenet.py From CapsNet-Keras with MIT License | 5 votes |
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()