def fetch_x_y(data, limit): batch, x, y = [], [], [] random_batch = [] for i in xrange(batch_size): # randomly fetch batch random_batch.append(data[random.randint(0, limit - 1)]) for npyFile in random_batch: loaded_scene = np.load(npyFile) scene = utils.npy_cutter(loaded_scene, scene_shape) batch.append(scene) batch = np.reshape(batch, (-1, scene_shape[0], scene_shape[1], scene_shape[2])) x = batch[:, 0:scene_shape[0], 0:scene_shape[1], 0:halfed_scene_shape] # input y = batch[:, 0:scene_shape[0], 0:scene_shape[1], halfed_scene_shape:scene_shape[2]] # gt x = np.reshape(x, (-1, scene_shape[0] * scene_shape[1] * halfed_scene_shape)) y = np.reshape(y, (-1, scene_shape[0] * scene_shape[1] * halfed_scene_shape)) return x, y
def fetch_x_y(data, limit): batch, x, y = [], [], [] random_batch = [] for i in xrange(batch_size): # randomly fetch batch random_batch.append(data[random.randint(0, limit - 1)]) for npyFile in random_batch: loaded_scene = np.load(npyFile) scene = utils.npy_cutter(loaded_scene, scene_shape) batch.append(scene) batch = np.reshape(batch, (-1, scene_shape[0], scene_shape[1], scene_shape[2])) return batch
def show_result(sess): logging.info("Creating ply files...") print("Creating ply files...") #////////////////////////////////////////////////////////////////////// for counter in range(num_of_vis_batch): trData, trLabel = [], [] batch_arr = [] batch_arr_2d = [] bs = 0 test_data = utils.fetch_random_batch(train_directory, batch_size) for test in test_data: loaded_file = np.load(test) batch_arr.append(utils.npy_cutter(loaded_file, scene_shape)) bs += 1 batch_arr = np.reshape( batch_arr, (bs, scene_shape[0], scene_shape[1], scene_shape[2])) trData = batch_arr[:, 0:scene_shape[0], 0:scene_shape[1], 0:halfed_scene_shape] # input trLabel = batch_arr[:, 0:scene_shape[0], 0:scene_shape[1], halfed_scene_shape:scene_shape[2]] # gt trData = np.reshape( trData, (-1, scene_shape[0] * scene_shape[1] * halfed_scene_shape)) score = sess.run(ConvNet_class.score, feed_dict={ x: trData, keepProb: 1.0, phase: False }) score = np.reshape(score, (-1, scene_shape[0], scene_shape[1], halfed_scene_shape, classes_count)) score = np.argmax(score, 4) score = np.reshape( score, (-1, scene_shape[0], scene_shape[1], halfed_scene_shape)) pre, rec = utils.precision_recall(score, trLabel, batch_size, classes_count) precision += pre recall += rec accu1, accu2 = accuFun(sess, trData, trLabel, bs) accu1_all += accu1 accu2_all += accu2 logging.info("A1: %g, A2: %g" % (accu1, accu2)) print("A1: %g, A2: %g" % (accu1, accu2)) print precision / num_of_vis_batch * 1.0 print recall / num_of_vis_batch * 1.0 print accu1_all / num_of_vis_batch * 1.0 print accu2_all / num_of_vis_batch * 1.0 #////////////////////////////////////////////////////////////////////// sys.exit(0) bs = 0 trData, trLabel = [], [] batch_arr = [] # test_data = utils.fetch_random_batch(test_directory, batch_size) # for test in test_data: # loaded_file = np.load(test) # batch_arr.append(utils.npy_cutter(loaded_file, scene_shape)) # bs += 1 # batch_arr = np.reshape( batch_arr, ( bs, scene_shape[0], scene_shape[1], scene_shape[2] )) # trData = batch_arr[ :, 0:scene_shape[0], 0:scene_shape[1], 0:halfed_scene_shape ] # input # trLabel = batch_arr[ :, 0:scene_shape[0], 0:scene_shape[1], halfed_scene_shape:scene_shape[2] ] # gt # trData = np.reshape(trData, (-1, scene_shape[0] * scene_shape[1] * halfed_scene_shape)) # accu1, accu2 = accuFun(sess, trData, trLabel, bs) # logging.info("A1: %g, A2: %g" % (accu1, accu2)) # print ("A1: %g, A2: %g" % (accu1, accu2)) for item in glob.glob(directory + "/*.ply"): os.remove(item) batch_arr = [] name_arr = [] counter = 0 for item in glob.glob(test_directory + '*.npy'): name_arr.append(str(item[12:])) loaded_file = np.load(item) batch_arr.append(utils.npy_cutter(loaded_file, scene_shape)) counter += 1 # if counter == batch_size: batch_arr = np.reshape( batch_arr, (-1, scene_shape[0], scene_shape[1], scene_shape[2])) trData = batch_arr[:, 0:scene_shape[0], 0:scene_shape[1], 0:halfed_scene_shape] # input trLabel = batch_arr[:, 0:scene_shape[0], 0:scene_shape[1], halfed_scene_shape:scene_shape[2]] # gt trData = np.reshape( trData, (-1, scene_shape[0] * scene_shape[1] * halfed_scene_shape)) score = sess.run(ConvNet_class.score, feed_dict={ x: trData, keepProb: 1.0, phase: False }) score = np.reshape(score, (counter, scene_shape[0], scene_shape[1], halfed_scene_shape, classes_count)) score = np.argmax(score, 4) trData = np.reshape( trData, (-1, scene_shape[0], scene_shape[1], halfed_scene_shape)) for i in range(counter): # loaded_file = np.load(test_data[i]) # scene = utils.npy_cutter(loaded_file, scene_shape) trData_i = trData[i, :, :, :] trData_i = np.reshape( trData_i, (scene_shape[0], scene_shape[1], halfed_scene_shape)) score_i = score[i, :, :, :] score_i = np.reshape( score_i, (scene_shape[0], scene_shape[1], halfed_scene_shape)) empty_scene = np.zeros((84, 44, 42)) empty_space = np.zeros((scene_shape[0], scene_shape[1], 50)) empty_scene = np.concatenate((trData_i, empty_scene), axis=2) empty_scene = np.concatenate((empty_scene, empty_space), axis=2) gen_scn = np.concatenate((trData_i, score_i), axis=2) gen_scn = np.concatenate((empty_scene, gen_scn), axis=2) empty_space = np.zeros((scene_shape[0], scene_shape[1], 50)) gen_scn = np.concatenate((gen_scn, empty_space), axis=2) gen_scn = np.concatenate((gen_scn, batch_arr[i, :, :, :]), axis=2) output = open(directory + "/" + name_arr[i] + ".ply", 'w') ply = "" numOfVrtc = 0 for idx1 in range(gen_scn.shape[0]): for idx2 in range(gen_scn.shape[1]): for idx3 in range(gen_scn.shape[2]): if gen_scn[idx1][idx2][idx3] > 0: ply = ply + str(idx1) + " " + str(idx2) + " " + str( idx3) + str(utils.colors[int( gen_scn[idx1][idx2][idx3])]) + "\n" numOfVrtc += 1 output.write("ply" + "\n") output.write("format ascii 1.0" + "\n") output.write("comment VCGLIB generated" + "\n") output.write("element vertex " + str(numOfVrtc) + "\n") output.write("property float x" + "\n") output.write("property float y" + "\n") output.write("property float z" + "\n") output.write("property uchar red" + "\n") output.write("property uchar green" + "\n") output.write("property uchar blue" + "\n") output.write("property uchar alpha" + "\n") output.write("element face 0" + "\n") output.write("property list uchar int vertex_indices" + "\n") output.write("end_header" + "\n") output.write(ply) output.close() print(test_data[i][12:] + ".ply" + " is Done!") batch_arr = [] name_arr = [] counter = 0
def show_result(sess): logging.info("Creating ply files...") print("Creating ply files...") bs = 0 trData, trLabel = [], [] batch_arr = [] test_data = utils.fetch_random_batch(test_directory, 64) for test in test_data: loaded_file = np.load(test) batch_arr.append(utils.npy_cutter(loaded_file, scene_shape)) bs += 1 batch_arr = np.reshape( batch_arr, (bs, scene_shape[0], scene_shape[1], scene_shape[2])) trData = batch_arr[:, 0:scene_shape[0], 0:scene_shape[1], 0:halfed_scene_shape] # input trLabel = batch_arr[:, 0:scene_shape[0], 0:scene_shape[1], halfed_scene_shape:scene_shape[2]] # gt trData = np.reshape( trData, (-1, scene_shape[0] * scene_shape[1] * halfed_scene_shape)) score = sess.run(ConvNet_class.score, feed_dict={ x: trData, keepProb: 1.0, phase: False }) accu1, accu2 = accuFun(sess, trData, trLabel, bs) logging.info("A1: %g, A2: %g" % (accu1, accu2)) print("A1: %g, A2: %g" % (accu1, accu2)) for test in test_data: loaded_file = np.load(test) scene = utils.npy_cutter(loaded_file, scene_shape) trData, trLabel = [], [] trData = scene[0:scene_shape[0], 0:scene_shape[1], 0:halfed_scene_shape] # input trLabel = scene[0:scene_shape[0], 0:scene_shape[1], halfed_scene_shape:scene_shape[2]] # gt trData = np.reshape( trData, (-1, scene_shape[0] * scene_shape[1] * halfed_scene_shape)) score = sess.run(ConvNet_class.score, feed_dict={ x: trData, keepProb: 1.0, phase: False }) score = np.reshape(score, (scene_shape[0], scene_shape[1], halfed_scene_shape, classes_count)) score = np.argmax(score, 3) score = np.reshape( score, (scene_shape[0], scene_shape[1], halfed_scene_shape)) score = score[0:scene_shape[0], 0:scene_shape[1], 0:halfed_scene_shape] trData = np.reshape( trData, (scene_shape[0], scene_shape[1], halfed_scene_shape)) gen_scn = np.concatenate((trData, score), axis=2) empty_space = np.zeros((10, 44, 84)) gen_scn = np.concatenate((gen_scn, empty_space), axis=0) gen_scn = np.concatenate((gen_scn, scene), axis=0) output = open(directory + "/" + test[10:] + ".ply", 'w') ply = "" numOfVrtc = 0 for idx1 in range(gen_scn.shape[0]): for idx2 in range(gen_scn.shape[1]): for idx3 in range(gen_scn.shape[2]): if gen_scn[idx1][idx2][idx3] > 0: ply = ply + str(idx1) + " " + str(idx2) + " " + str( idx3) + str(utils.colors[int( gen_scn[idx1][idx2][idx3])]) + "\n" numOfVrtc += 1 output.write("ply" + "\n") output.write("format ascii 1.0" + "\n") output.write("comment VCGLIB generated" + "\n") output.write("element vertex " + str(numOfVrtc) + "\n") output.write("property float x" + "\n") output.write("property float y" + "\n") output.write("property float z" + "\n") output.write("property uchar red" + "\n") output.write("property uchar green" + "\n") output.write("property uchar blue" + "\n") output.write("property uchar alpha" + "\n") output.write("element face 0" + "\n") output.write("property list uchar int vertex_indices" + "\n") output.write("end_header" + "\n") output.write(ply) output.close() logging.info(test + ".ply" + " is Done!") print(test + ".ply" + " is Done!") logging.info("A1: %g, A2: %g" % (accu1, accu2)) print("A1: %g, A2: %g" % (accu1, accu2))
valid_cost = [] train_accu1 = [] train_accu2 = [] valid_accu1 = [] valid_accu2 = [] batch = [] accu1tr, accu2tr = 0, 0 try: while (epoch < max_epoch): for npyFile in glob.glob(data_directory + '*.npy'): trData, trLabel = [], [] if counter < batch_size: loaded_scene = np.load(npyFile) scene = utils.npy_cutter(loaded_scene, scene_shape) batch.append(scene) counter += 1 else: counter = 0 batch = np.reshape(batch, (-1, scene_shape[0], scene_shape[1], scene_shape[2])) trData = batch[:, 0:scene_shape[0], 0:scene_shape[1], 0:halfed_scene_shape] # input trLabel = batch[:, 0:scene_shape[0], 0:scene_shape[1], halfed_scene_shape: scene_shape[2]] # gt trData = np.reshape(
def show_result(sess): print("Creating ply files...") cur_vis_batch = 0 trData, trLabel = [], [] batch_arr = [] for item in glob.glob(directory + "/*.ply"): os.remove(item) batch_arr = [] name_arr = [] counter = 0 for item in glob.glob(train_directory + '*.npy'): name_arr.append(str(item[12:])) loaded_file = np.load(item) batch_arr.append(utils.npy_cutter(loaded_file, scene_shape)) counter += 1 if counter == batch_size: batch_arr = np.reshape( batch_arr, (-1, scene_shape[0], scene_shape[1], scene_shape[2])) trData = batch_arr[:, 0:scene_shape[0], 0:scene_shape[1], 0:halfed_scene_shape] # input trLabel = batch_arr[:, 0:scene_shape[0], 0:scene_shape[1], halfed_scene_shape:scene_shape[2]] # gt trData = np.reshape( trData, (-1, scene_shape[0] * scene_shape[1] * halfed_scene_shape)) score = sess.run(ConvNet_class.generator, feed_dict={ x: trData, keepProb: 1.0, phase: False }) score = np.reshape(score, (counter, scene_shape[0], scene_shape[1], halfed_scene_shape, classes_count)) score = np.argmax(score, 4) trData = np.reshape( trData, (-1, scene_shape[0], scene_shape[1], halfed_scene_shape)) for i in range(counter): trData_i = trData[i, :, :, :] trData_i = np.reshape( trData_i, (scene_shape[0], scene_shape[1], halfed_scene_shape)) score_i = score[i, :, :, :] score_i = np.reshape( score_i, (scene_shape[0], scene_shape[1], halfed_scene_shape)) empty_scene = np.zeros((84, 44, 42)) empty_space = np.zeros((scene_shape[0], scene_shape[1], 50)) empty_scene = np.concatenate((trData_i, empty_scene), axis=2) empty_scene = np.concatenate((empty_scene, empty_space), axis=2) gen_scn = np.concatenate((trData_i, score_i), axis=2) gen_scn = np.concatenate((empty_scene, gen_scn), axis=2) empty_space = np.zeros((scene_shape[0], scene_shape[1], 50)) gen_scn = np.concatenate((gen_scn, empty_space), axis=2) gen_scn = np.concatenate((gen_scn, batch_arr[i, :, :, :]), axis=2) output = open(directory + "/" + name_arr[i] + ".ply", 'w') ply = "" numOfVrtc = 0 for idx1 in range(gen_scn.shape[0]): for idx2 in range(gen_scn.shape[1]): for idx3 in range(gen_scn.shape[2]): if gen_scn[idx1][idx2][idx3] > 0: ply = ply + str(idx1) + " " + str( idx2) + " " + str(idx3) + str( utils.colors[int( gen_scn[idx1][idx2][idx3])]) + "\n" numOfVrtc += 1 output.write("ply" + "\n") output.write("format ascii 1.0" + "\n") output.write("comment VCGLIB generated" + "\n") output.write("element vertex " + str(numOfVrtc) + "\n") output.write("property float x" + "\n") output.write("property float y" + "\n") output.write("property float z" + "\n") output.write("property uchar red" + "\n") output.write("property uchar green" + "\n") output.write("property uchar blue" + "\n") output.write("property uchar alpha" + "\n") output.write("element face 0" + "\n") output.write("property list uchar int vertex_indices" + "\n") output.write("end_header" + "\n") output.write(ply) output.close() print(name_arr[i][12:] + ".ply" + " is Done!") batch_arr = [] name_arr = [] counter = 0 cur_vis_batch += 1 if num_of_vis_batch == cur_vis_batch: sys.exit(0)