Ejemplo n.º 1
0
lr_np = opt.lr
beta_np = opt.beta1

# cast some control-variables for the loss-weights
gan_tf = tf.placeholder(tf.float32, shape=[])
l1_weight_tf = tf.placeholder(tf.float32, shape=[])
l1_sparse_weight_tf = tf.placeholder(tf.float32, shape=[])
TV_weight_tf = tf.constant(TV_weight_np)
lr_tf = tf.constant(lr_np)
beta1_tf = tf.constant(beta_np)

# inputs and targets are [batch_size, height, width, channels]
C2Pmodel = model.create_model(inputs_tf, outputs_tf, opt.ndf, opt.ngf, gan_tf, l1_weight_tf, l1_sparse_weight_tf, lr_tf, beta1_tf, TV_weight_tf)

# reverse any processing on images so they can be written to disk or displayed to user
inputs = data.deprocess_tf(C2Pmodel.inputs)
targets = data.deprocess_tf(C2Pmodel.targets)
outputs = data.deprocess_tf(C2Pmodel.outputs)
outputs_psf = data.deprocess_tf(C2Pmodel.outputs_psf)

def convert(image):
    image = data.norm_min_max_tf(image)
    return tf.image.convert_image_dtype(image, dtype=tf.uint8, saturate=True)

with tf.name_scope("convert_inputs"):
    converted_inputs = convert(inputs)

with tf.name_scope("convert_targets"):
    converted_targets = convert(targets)

with tf.name_scope("convert_outputs"):
# determine the sizes 
roisize = 64
EPS = 1e-12
   
# create placeholders for batchfeeding
im_xdim, im_ydim = scale_size, scale_size
inputs_tf = tf.placeholder(tf.float32, shape=(batch_size, im_xdim, im_ydim, 1), name='inputs_tf')
outputs_tf = tf.placeholder(tf.float32, shape=(batch_size, im_xdim, im_ydim, 1), name='outputs_tf')
spikes_tf = tf.placeholder(tf.float32, shape=(batch_size, im_xdim, im_ydim, 1), name='spikes_tf')

# inputs and targets are [batch_size, height, width, channels]
C2Pmodel = model.create_model(inputs_tf, outputs_tf, ndf, ngf, EPS, gan_weight, l1_weight, l1_sparse_weight, lr, beta1)

# reverse any processing on images so they can be written to disk or displayed to user
outputs = data.deprocess_tf(C2Pmodel.outputs)
outputs = data.norm_min_max_tf(outputs)
outputs = tf.reduce_sum(outputs, axis=[0,3], name='outputs')
 
# define saver
saver = tf.train.Saver(max_to_keep=1)

# Initialize the variables (i.e. assign their default value)
init = tf.global_variables_initializer()
print("Variables have been initialized!")    

with tf.Session() as sess:
#sess = tf.InteractiveSession()
#sess = tf.Session()

    # Run the initializer