Пример #1
0
show_result = True
# If save_result_filename == None or "" then we don't save an image
save_result_filename = "result-1-1024-10000"
# Append the datetime to the save_result_filename
import datetime
d = datetime.datetime.now()
save_result_filename += "-" + str(d.year) + "-" + str(d.month) + "-" + str(d.day)
save_result_filename += "-" + str(d.hour) + str(d.minute)
print "Saving results to", save_result_filename

# read_amat_file is in helper_functions
[X, Y] = read_amat_file(training_file_name, sample_size)
print "Training File Read, starting fit"

ae = CAE(epochs=num_epochs, n_hiddens=num_hidden_units, schatten_p = schatten_p_value, save_results_file=save_result_filename)
ae.fit(X, True)

r_X = ae.reconstruct(X[0])

# Show the first image and the reconstructed image
fig = plt.figure(1, (1,2))
grid = ImageGrid(fig, 111, nrows_ncols = (1, 2), axes_pad=0.1)
grid[0].imshow(numpy.reshape(X[0], (28,-1)))
grid[1].imshow(numpy.reshape(r_X, (28,-1)))

if save_result_filename != None and save_result_filename != "":
  plt.savefig(save_result_filename + ".png")
if show_result:
  plt.show()