print('[Data] outputs: %s' % ' x '.join(map(str, outputs.shape))) print('[Data] inputs: %s' % ' x '.join(map(str, inputs.shape))) print('[Data] space: %s' % ' x '.join(map(str, space.shape))) n_observations = config['n_observations'] for i in range(min(25, outputs.shape[0])): #n = random.randint(0, outputs[-1].shape[0]) n = i print('[Data] visualizing %s %d/%d' % (set, (n + 1), outputs.shape[0])) for k in range(n_observations): slices = [] for j in range(2, outputs[n][0].shape[0] - 2, 2): slices.append(j) outputs_inputs = outputs[n][0].copy() outputs_inputs[inputs[n][k] == 1] = 2 space_inputs = space[n][k].copy() space_inputs[inputs[n][k] == 1] = 2 mask = np.logical_and(inputs[n][k] == 1, space[n][k] == 1) space_inputs[mask] = 3 visualization.plot_specific_slices([ outputs[n][0], inputs[n][k], space[n][k], outputs_inputs, space_inputs ], slices, '%s_%d_%d.png' % (set, n, k), 0, 0, 3)
n = i print('[Data] visualizing %s %d/%d' % (set, (n + 1), filled.shape[0])) for k in range(n_observations): slices = [] for j in range(2, filled[n][0].shape[0] - 2, 2): slices.append(j) filled_inputs = filled[n][0].copy() filled_inputs[inputs[n][k] == 1] = 2 space_inputs = space[n][k].copy() space_inputs[inputs[n][k] == 1] = 2 mask = np.logical_and(inputs[n][k] == 1, space[n][k] == 1) space_inputs[mask] = 3 if config['sdf']: sdf_bin = sdfs[n][0].copy() sdf_bin[sdf_bin >= 0] = 0 sdf_bin[sdf_bin < 0] = 1 visualization.plot_specific_slices([ filled[n][0], inputs[n][k], space[n][k], filled_inputs, space_inputs, sdf_bin ], slices, '%s_%d_%d.png' % (set, n, k), 0, 0, 3) else: visualization.plot_specific_slices([ filled[n][0], inputs[n][k], space[n][k], filled_inputs, space_inputs ], slices, '%s_%d_%d.png' % (set, n, k), 0, 0, 3)
#for level in range(config['levels'] + 1): # volumes.append(outputs[level][n][0]) # volumes.append(filled[level][n][0]) #visualization.plot_slices(volumes, dataset + '_' + str(n) + '.png', 0, 0, np.max(labeled)) #plt.clf() #plt.imshow(depths[n]) #plt.savefig(dataset + '_' + str(n) + '_depth.png') slices = [] for j in range(2, filled[n][0].shape[0] - 2, 1): slices.append(j) filled_inputs = filled[n][0].copy() filled_inputs[inputs[n][0] == 1] = 2 space_inputs = space[n][0].copy() space_inputs[inputs[n][0] == 1] = 2 mask = np.logical_and(inputs[n][0] == 1, space[n][0] == 1) space_inputs[mask] = 3 real_sdf_bin = real_sdf[n][0].copy() real_sdf_bin[real_sdf_bin >= 0] = 0 real_sdf_bin[real_sdf_bin < 0] = 1 visualization.plot_specific_slices([ filled[n][0], inputs[n][0], space[n][0], filled_inputs, space_inputs, real_sdf_bin ], slices, dataset + '_' + str(n) + '.png', 0, 0, 3) #visualization.plot_specific_slices([real_sdf[n][0], input_sdf[n][0]], slices, dataset + '_' + str(n) + '_sdf.png', 0, min(np.min(real_sdf[n][0]), np.min(input_sdf[n][0])), max(np.max(real_sdf[n][0]), np.max(input_sdf[n][0])))
# print(' filtered (%d/%d %d/%d %f/%f' % ( # n_voxels, config['min_input_voxels'], # n_space, config['min_space_voxels'], # distance, config['max_bounding_box_distance'] # )) #else: # print(' not filtered (%d/%d %d/%d %f/%f' % ( # n_voxels, config['min_input_voxels'], # n_space, config['min_space_voxels'], # distance, config['max_bounding_box_distance'] # )) slices = [] for j in range(2, inputs[n][0].shape[0] - 2, 1): slices.append(j) visualization.plot_specific_slices( [inputs[n][0], full_space[n][0], part_space[n][0]], slices, dataset + '_' + str(n) + '.png') #visualization.plot_specific_slices([inputs_combined_gt[n][0], inputs_gt[n][0], full_space_gt[n][0], part_space_gt[n][0], inputs_gt[n][1], full_space_gt[n][1], part_space_gt[n][1], inputs_gt[n][2], full_space_gt[n][2], part_space_gt[n][2]], slices, dataset + '_' + str(n) + '_gt.png') #visualization.plot_specific_slices([inputs_sdf_combined_gt[n][0], inputs_sdf[n][0]], slices, dataset + '_' + str(n) + '_sdf.png', 0, np.min(inputs_sdf[n]),np.max(inputs_sdf[n])) #visualization.plot_volumes(space[n][0], inputs[n][0], '', 10, 1) #visualization.plot_volume_mayavi(inputs[n][0]) #visualization.plot_volume_mayavi(full_space[n][0]) #visualization.plot_volume_mayavi(part_space[n][0]) #plt.imshow(depths[n, :, :, 0]) #plt.imshow(cylindral[n]) #plt.show()
print('[Data] read ' + common.filename(config, 'input_file', '_f.h5', dataset)) inputs_sdf = utils.read_hdf5( common.filename(config, 'input_sdf_file', '_f.h5', dataset)) print('[Data] read ' + common.filename(config, 'input_sdf_file', '_f.h5', dataset)) inputs_tsdf = utils.read_hdf5( common.filename(config, 'input_tsdf_file', '_f.h5', dataset)) print('[Data] read ' + common.filename(config, 'input_tsdf_file', '_f.h5', dataset)) inputs_ltsdf = utils.read_hdf5( common.filename(config, 'input_ltsdf_file', '_f.h5', dataset)) print('[Data] read ' + common.filename(config, 'input_ltsdf_file', '_f.h5', dataset)) for i in range(min(25, inputs.shape[0])): n = i #random.randint(0, inputs.shape[0] - 1) print('[Data] visualizing %s %d/%d' % (dataset, (n + 1), inputs.shape[0])) slices = [] for j in range(2, inputs[n][0].shape[0] - 2, 1): slices.append(j) visualization.plot_specific_slices([ inputs[n][0] * np.max(inputs_sdf[n][0]), inputs_sdf[n][0], inputs_tsdf[n][0], inputs_ltsdf[n][0] ], slices, dataset + '_' + str(n) + '.png', 0, 0, np.max(inputs_sdf[n][0]))
input_sdfs = utils.read_hdf5(common.filename(config, 'input_sdf_file')) print('[Data] read ' + common.filename(config, 'input_sdf_file')) input_ltsdfs = utils.read_hdf5(common.filename(config, 'input_ltsdf_file')) print('[Data] read ' + common.filename(config, 'input_ltsdf_file')) output_sdfs = utils.read_hdf5(common.filename(config, 'sdf_file')) print('[Data] reading ' + common.filename(config, 'sdf_file')) output_ltsdfs = utils.read_hdf5(common.filename(config, 'ltsdf_file')) print('[Data] reading ' + common.filename(config, 'ltsdf_file')) print('[Data] input_sdfs: %s' % ' x '.join(map(str, input_sdfs.shape))) print('[Data] input_ltsdfs: %s' % ' x '.join(map(str, input_ltsdfs.shape))) print('[Data] output_sdfs: %s' % ' x '.join(map(str, output_sdfs.shape))) print('[Data] output_ltsdfs: %s' % ' x '.join(map(str, output_ltsdfs.shape))) for i in range(min(25, output_sdfs.shape[0])): #n = random.randint(0, filled[-1].shape[0]) n = i print('[Data] visualizing %s %d/%d' % (set, (n + 1), output_sdfs.shape[0])) slices = [] for j in range(2, output_sdfs[n][0].shape[0] - 2, 2): slices.append(j) visualization.plot_specific_slices([ output_sdfs[n][0], output_ltsdfs[n][0], input_sdfs[n][0], input_ltsdfs[n][0] ], slices, set + '_' + str(n) + '.png', 0, np.min(output_sdfs[n][0]), max(np.max(output_sdfs[n][0]), np.max(input_sdfs[n][0])))
print('[Data] Usage python 13_ply_observations.py config_folder') exit(1) config_folder = sys.argv[1] + '/' assert os.path.exists( config_folder), 'directory %s does not exist' % config_folder config_file = config_folder + 'training_prior.json' assert os.path.exists(config_file) print('[Data] reading ' + config_file) config = utils.read_json(config_file) filled_file = common.filename(config, 'filled_file') filled = utils.read_hdf5(filled_file) print('[Data] read ' + filled_file) slices = [] for j in range(2, filled[0][0].shape[0] - 2, 2): slices.append(j) N = filled.shape[0] statistics = np.sum(np.squeeze(filled), axis=0) / float(N) statistics = 1 - statistics statistics = (0.75 * statistics + 0.25 * 1)**2 visualization.plot_specific_slices([statistics], slices) statistics_file = common.filename(config, 'training_statistics_file') utils.write_hdf5(statistics_file, statistics) print('[Data] wrote ' + statistics_file)