From 950b5d8eee9676d60800fd920fa8b116128bc2bd Mon Sep 17 00:00:00 2001 From: martham93 Date: Wed, 16 Jun 2021 17:49:07 -0600 Subject: [PATCH 1/2] error handling fix --- task-tfrecords/generate_datanpz.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/task-tfrecords/generate_datanpz.py b/task-tfrecords/generate_datanpz.py index 03d10e3c..42f4b835 100644 --- a/task-tfrecords/generate_datanpz.py +++ b/task-tfrecords/generate_datanpz.py @@ -149,6 +149,7 @@ def make_datanpz(dest_folder, imagery, supertile, y_vals = [] for tile in tiles: + print(tile) image_file = glob.glob(dest_folder + '/' + 'tiles/' + tile + '*')[0] try: img = Image.open(image_file) @@ -160,18 +161,23 @@ def make_datanpz(dest_folder, imagery, supertile, continue np_image = np.array(img) + + if np_image.shape == (256, 256, 2): + print('bad tile') + print(tile) + img.close() - if not supertile: + if not supertile and not np_image.shape == (256, 256, 2): try: np_image = np_image.reshape((256, 256, 3)) # 4 channels returned from some endpoints, but not all + x_vals.append(np_image) + y_vals.append(labels[tile]) except ValueError: np_image = np_image.reshape((256, 256, 4)) np_image = np_image[:, :, :3] - - #focusing just on classification - x_vals.append(np_image) - y_vals.append(labels[tile]) + x_vals.append(np_image) + y_vals.append(labels[tile]) # Convert lists to numpy arrays x_vals = np.array(x_vals, dtype=np.uint8) From 2b5208d19fda4870613695ffa2f018619d60c947 Mon Sep 17 00:00:00 2001 From: martham93 Date: Wed, 16 Jun 2021 17:55:57 -0600 Subject: [PATCH 2/2] fix print --- task-tfrecords/generate_datanpz.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/task-tfrecords/generate_datanpz.py b/task-tfrecords/generate_datanpz.py index 42f4b835..657fba74 100644 --- a/task-tfrecords/generate_datanpz.py +++ b/task-tfrecords/generate_datanpz.py @@ -149,7 +149,6 @@ def make_datanpz(dest_folder, imagery, supertile, y_vals = [] for tile in tiles: - print(tile) image_file = glob.glob(dest_folder + '/' + 'tiles/' + tile + '*')[0] try: img = Image.open(image_file) @@ -163,8 +162,7 @@ def make_datanpz(dest_folder, imagery, supertile, np_image = np.array(img) if np_image.shape == (256, 256, 2): - print('bad tile') - print(tile) + print("bad tile: {}".format(tile)) img.close()