Created
February 18, 2018 14:21
-
-
Save JoshBroomberg/d64b0f2712623827d26fa957f0a66e8e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
compressed_image_data_train = pca.transform(image_data_train) | |
uncompressed_image_data_train = pca.inverse_transform(compressed_image_data_train) | |
fig=plt.figure(figsize=(12, 20)) | |
columns = 4 | |
rows = 8 | |
for i in range(1, 33, 4): | |
component_id = int(i/4) | |
eigen_image = image_from_component_values(pca.components_[component_id]) | |
inverted_egein_image = PIL.ImageOps.invert(eigen_image) | |
most_similar_id = (np.argmax(compressed_image_data_train[:, component_id])) | |
most_dissimilar_id = (np.argmin(compressed_image_data_train[:, component_id])) | |
fig.add_subplot(rows, columns, i) | |
plt.imshow(eigen_image) | |
fig.add_subplot(rows, columns, i+1) | |
similar_image = plt.imshow( | |
raw_image_data[most_similar_id, :].reshape(IMAGE_SIZE[1], IMAGE_SIZE[0], 3)) | |
fig.add_subplot(rows, columns, i+2) | |
similar_image = plt.imshow( | |
raw_image_data[most_dissimilar_id, :].reshape(IMAGE_SIZE[1], IMAGE_SIZE[0], 3)) | |
fig.add_subplot(rows, columns, i+3) | |
plt.imshow(inverted_egein_image) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment