#except: # pass b2 = time() if((step[1]==float("Inf") or step[1]==0) and save): save = False for j in range(8): cl.visual.save(image[j], "dump/img/source/"+str(j)) for k in range(4): cl.visual.save(step[2][j,:,:,k], "dump/img/f"+str(k)+"/"+str(j)) cl.visual.save(step[3][j,:,:,k], "dump/tmp/f"+str(k)+"/"+str(j)) cl.visual.save(template[j], "dump/tmp/template/"+str(j)) raise Exception('error') b = time() print('iteration',i, format(b-a, '.2f'), format(step[1], '.2f'), np.mean(label) ) except KeyboardInterrupt(): print('exiting') finally: cl.tf.global_session().model_save() print('saved') cl.tf.global_session().close_sess() # write this def evaluate(model, test_data, testing_steps, i): return if __name__ == "__main__": hparams = cl.hparams(name="default") train(hparams)
return tf.train.Feature(int64_list=tf.train.Int64List(value=[value])) def _bytes_feature(value): return tf.train.Feature(bytes_list=tf.train.BytesList(value=[value])) def convert_to(source, filename, size): """Converts a dataset to tfrecords.""" print('Writing', filename) writer = tf.python_io.TFRecordWriter(filename) for i in range(size): t1 = time.time() image = source.get_sequence() t2 = time.time() print(t2 - t1) image_raw = np.asarray(image, dtype=np.uint8).tostring() ex = tf.train.Example(features=tf.train.Features( feature={'image': _bytes_feature(image_raw)})) writer.write(ex.SerializeToString()) writer.close() print('Saved ', size) if __name__ == "__main__": hparams = cl.hparams(name="preprocessing") d = DataGenerator(hparams) convert_to(d, hparams.tfrecord_train_dest, hparams.train_size) convert_to(d, hparams.tfrecord_test_dest, hparams.test_size)
#FIXME this to go to hparams s_width = 512 BATCH_SIZE = 4 size = 100 width = 160 #MODEL_DIR = 'logs/NCCNet_flyem/' features = { "inputs":"image:0", "outputs": "output/image_0:0"} #features = {"inputs": "image:0", "outputs": "add_96:0"} #features = { "inputs":"image:0", "outputs": "output/image:0"} # Init hparams = cl.hparams(name="evaluation") #d = Data(hparams, random=False) #print('data loaded') #image, template, _ = d.get_batch(switching=False) #Sample test print('model loaded') def get_batch(): #image, template, _ = d.get_batch(switching=False) #template = np.pad(template, 128, mode='constant') image = np.zeros((BATCH_SIZE,s_width,s_width,3), dtype=np.uint8) template = np.zeros((BATCH_SIZE,s_width,s_width,3), dtype=np.uint8) i=0