Beispiel #1
0
	def test(self, X_test_r, reconstruct = True):
		costs = []
		num_batch_valid = len(X_test)//BATCH_SIZE

		for j in range(num_batch_valid):
			cost = valid_fn(
				X_test[j*BATCH_SIZE: (j+1)*BATCH_SIZE],
				X_test_r[j*BATCH_SIZE: (j+1)*BATCH_SIZE]
				)
			costs.append(cost)

		self.X = self.generate_fn(self.generate_routine, 32, 32, 25)
		# model.save_params('{}/epoch_{}_val_error_{}.pkl'.format(OUT_DIR,i, numpy.mean(costs)))
		if reconstruct:
			reconstruction = generate_routine(X_test[:25])

			plot_25_figure(self.X, '{}/epoch_{}_val_error_{}_gen_images.jpg'.format(OUT_DIR, i, numpy.mean(costs)), num_channels = 3)
			plot_25_figure(reconstruction, '{}/epoch_{}_reconstructed.jpg'.format(OUT_DIR, i), num_channels = 3)

		print "Validation cost after epoch {}: {}".format(i+1, numpy.mean(costs))
		self.errors['validation'].append(numpy.mean(costs))
Beispiel #2
0
	for j in range(num_batch_valid):
		cost = valid_fn(
			X_test[j*BATCH_SIZE: (j+1)*BATCH_SIZE],
			X_test_r[j*BATCH_SIZE: (j+1)*BATCH_SIZE]
			)
		costs.append(cost)

		if (j+1) % PRINT_EVERY == 0:
			print ("Validation: epoch {}, iter {}, cost {}".format(i,j+1,numpy.mean(costs)))

	model.save_params('{}/epoch_{}_val_error_{}.pkl'.format(OUT_DIR,i, numpy.mean(costs)))

	X = generate_fn(generate_routine, 32, 32, 25)

	reconstruction = generate_routine(X_test[:25])

	plot_25_figure(X, '{}/epoch_{}_val_error_{}_gen_images.jpg'.format(OUT_DIR, i, numpy.mean(costs)), num_channels = 3)
	plot_25_figure(reconstruction, '{}/epoch_{}_reconstructed.jpg'.format(OUT_DIR, i), num_channels = 3)

	print("Validation cost after epoch {}: {}".format(i+1, numpy.mean(costs)))
	errors['validation'].append(numpy.mean(costs))

	if i % 2 == 0:
		save(errors, '{}/epoch_{}_NLL.pkl'.format(OUT_DIR, i))





Beispiel #3
0
        if (j + 1) % PRINT_EVERY == 0:
            print("Training: epoch {}, iter {}, cost {}".format(
                i, j + 1, numpy.mean(costs)))

    print("Training cost for epoch {}: {}".format(i + 1, numpy.mean(costs)))
    errors['training'].append(numpy.mean(costs))

    val_error = validate()
    errors['validation'].append(val_error)

    model.save_params('{}/epoch_{}_val_error_{}.pkl'.format(
        OUT_DIR, i, val_error))  #parameters are saved after every epoch

    X = generate_fn(generate_routine, 28, 28,
                    25)  # 25 images are generated after every epoch

    reconstruction = generate_routine(X_test[:25])[:, :, :, 0]

    plot_25_figure(
        X, '{}/epoch_{}_val_error_{}_gen_images.jpg'.format(
            OUT_DIR, i, val_error))
    plot_25_figure(reconstruction,
                   '{}/epoch_{}_reconstructed.jpg'.format(OUT_DIR, i))

    print("Validation cost after epoch {}: {}".format(i + 1, val_error))

    if i % 2 == 0:
        save(
            errors, '{}/epoch_{}_NLL.pkl'.format(OUT_DIR, i)
        )  #NLL upto ith epoch stored after every 2 epochs. Too much redundancy here.
Beispiel #4
0
		num_iters += 1

		if (j+1) % PRINT_EVERY == 0:
			print ("Training: epoch {}, iter {}, cost {}".format(i,j+1,numpy.mean(costs)))

	print("Training cost for epoch {}: {}".format(i+1, numpy.mean(costs)))
	errors['training'].append(numpy.mean(costs))

	val_error = validate()	
	errors['validation'].append(val_error)

	model.save_params('{}/epoch_{}_val_error_{}.pkl'.format(OUT_DIR,i, val_error)) #parameters are saved after every epoch

	X = generate_fn(generate_routine, 28, 28, 25) # 25 images are generated after every epoch

	reconstruction = generate_routine(X_test[:25])[:,:,:,0]

	plot_25_figure(X, '{}/epoch_{}_val_error_{}_gen_images.jpg'.format(OUT_DIR, i, val_error))
	plot_25_figure(reconstruction, '{}/epoch_{}_reconstructed.jpg'.format(OUT_DIR, i))

	print("Validation cost after epoch {}: {}".format(i+1, val_error))

	if i % 2 == 0:
		save(errors, '{}/epoch_{}_NLL.pkl'.format(OUT_DIR, i)) #NLL upto ith epoch stored after every 2 epochs. Too much redundancy here. 





Beispiel #5
0
	for j in range(num_batch_valid):
		cost = valid_fn(
			X_test[j*BATCH_SIZE: (j+1)*BATCH_SIZE],
			X_test_r[j*BATCH_SIZE: (j+1)*BATCH_SIZE]
			)
		costs.append(cost)

		if (j+1) % PRINT_EVERY == 0:
			print ("Validation: epoch {}, iter {}, cost {}".format(i,j+1,numpy.mean(costs)))

	model.save_params('{}/epoch_{}_val_error_{}.pkl'.format(OUT_DIR,i, numpy.mean(costs)))

	X = generate_fn(generate_routine, 32, 32, 25)

	reconstruction = generate_routine(X_test[:25])

	plot_25_figure(X, '{}/epoch_{}_val_error_{}_gen_images.jpg'.format(OUT_DIR, i, numpy.mean(costs)), num_channels = 3)
	plot_25_figure(reconstruction, '{}/epoch_{}_reconstructed.jpg'.format(OUT_DIR, i), num_channels = 3)

	print("Validation cost after epoch {}: {}".format(i+1, numpy.mean(costs)))
	errors['validation'].append(numpy.mean(costs))

	if i % 2 == 0:
		save(errors, '{}/epoch_{}_NLL.pkl'.format(OUT_DIR, i))