text stringlengths 1 93.6k |
|---|
if mse > 2 or np.isnan(mse):
|
break
|
if epoch % FLAGS.log_step == 0:
|
if not os.path.exists(synthesis_dir):
|
os.makedirs(synthesis_dir)
|
data_io.saveVoxelsToMat(sample_voxels + voxel_mean, "%s/sample%04d.mat" % (synthesis_dir, epoch), cmin=0, cmax=1)
|
if not os.path.exists(checkpoint_dir):
|
os.makedirs(checkpoint_dir)
|
saver.save(sess, "%s/%s" % (checkpoint_dir, 'model.ckpt'), global_step=epoch)
|
if not os.path.exists(log_dir):
|
os.makedirs(log_dir)
|
plt.figure(1)
|
data_io.draw_graph(plt, des_loss_epoch, 'des_loss', log_dir, 'r')
|
plt.figure(2)
|
data_io.draw_graph(plt, recon_err_epoch, 'recon_error', log_dir, 'b')
|
def test():
|
assert FLAGS.ckpt != None, 'no model provided.'
|
cube_len = FLAGS.cube_len
|
scale = FLAGS.scale
|
batch_size = FLAGS.batch_size
|
test_dir = os.path.join(FLAGS.output_dir, FLAGS.category, 'test')
|
lr_size = cube_len // scale
|
obs = tf.placeholder(tf.float32, [None, cube_len, cube_len, cube_len, 1], name='obs_data')
|
syn = tf.placeholder(tf.float32, [None, cube_len, cube_len, cube_len, 1], name='syn_data')
|
low_res = tf.placeholder(tf.float32, [None, lr_size, lr_size, lr_size, 1], name='low_res')
|
down_syn = downsample(obs, scale)
|
up_syn = upsample(low_res, scale)
|
syn_res = descriptor(syn, reuse=False)
|
syn_langevin = langevin_dynamics(syn)
|
sr_res = obs + syn - avg_pool(syn, scale)
|
train_data = data_io.getObj(FLAGS.data_path, FLAGS.category, train=True, cube_len=cube_len, num_voxels=FLAGS.train_size)
|
test_data = data_io.getObj(FLAGS.data_path, FLAGS.category, train=False, cube_len=cube_len, num_voxels=FLAGS.test_size)
|
if not os.path.exists(test_dir):
|
os.makedirs(test_dir)
|
data_io.saveVoxelsToMat(test_data, "%s/observed_data.mat" % test_dir, cmin=0, cmax=1)
|
sample_size = len(test_data)
|
num_batches = int(math.ceil(sample_size / batch_size))
|
saver = tf.train.Saver()
|
with tf.Session() as sess:
|
sess.run(tf.global_variables_initializer())
|
print('Generating low resolution data')
|
test_data = test_data[..., np.newaxis]
|
up_samples = np.zeros(test_data.shape)
|
down_samples = np.zeros(shape=[sample_size, lr_size, lr_size, lr_size, 1])
|
for i in range(num_batches):
|
indices = slice(i * batch_size, min(sample_size, (i + 1) * batch_size))
|
obs_data = test_data[indices]
|
ds = sess.run(down_syn, feed_dict={obs: obs_data})
|
us = sess.run(up_syn, feed_dict={low_res: ds})
|
down_samples[indices] = ds
|
up_samples[indices] = us
|
data_io.saveVoxelsToMat(down_samples, "%s/down_sample.mat" % test_dir, cmin=0, cmax=1)
|
data_io.saveVoxelsToMat(up_samples, "%s/up_sample.mat" % test_dir, cmin=0, cmax=1)
|
voxel_mean = train_data.mean()
|
up_samples = up_samples - voxel_mean
|
print 'Loading checkpoint {}.'.format(FLAGS.ckpt)
|
saver.restore(sess, FLAGS.ckpt)
|
init_data = up_samples.copy()
|
sample_voxels = np.random.randn(sample_size, cube_len, cube_len, cube_len, 1)
|
for i in range(num_batches):
|
indices = slice(i * batch_size, min(sample_size, (i + 1) * batch_size))
|
us_data = init_data[indices]
|
# Langevin Sampling
|
y1 = sess.run(syn_langevin, feed_dict={syn: us_data})
|
sample_voxels[indices] = y1
|
data_io.saveVoxelsToMat(sample_voxels + voxel_mean, "%s/samples.mat" % test_dir, cmin=0, cmax=1)
|
if __name__ == '__main__':
|
if FLAGS.test:
|
test()
|
else:
|
train()
|
# <FILESEP>
|
# -*- coding: utf-8 -*-
|
#=========================================================================================================================================
|
import os
|
import random
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.