From e2f25d8f296d132da2478451941bc232b27044db Mon Sep 17 00:00:00 2001 From: zsdonghao Date: Thu, 22 Feb 2018 20:03:38 +0000 Subject: [PATCH 1/3] 1) try exception with Exception / 2) use enumerate instead of range(len()) --- tensorlayer/prepro.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tensorlayer/prepro.py b/tensorlayer/prepro.py index 85970e9f9..04af4c328 100644 --- a/tensorlayer/prepro.py +++ b/tensorlayer/prepro.py @@ -100,8 +100,10 @@ def apply_fn(results, i, data, kwargs): if thread_count is None: results = [None] * len(data) threads = [] - for i in range(len(data)): - t = threading.Thread(name='threading_and_return', target=apply_fn, args=(results, i, data[i], kwargs)) + # for i in range(len(data)): + # t = threading.Thread(name='threading_and_return', target=apply_fn, args=(results, i, data[i], kwargs)) + for i, d in enumerate(data): + t = threading.Thread(name='threading_and_return', target=apply_fn, args=(results, i, d, kwargs)) t.start() threads.append(t) else: @@ -120,7 +122,7 @@ def apply_fn(results, i, data, kwargs): if thread_count is None: try: return np.asarray(results) - except: + except Exception: return results else: return np.concatenate(results) From ac556abcbaaa642227237ccad1423a4ffd57feab Mon Sep 17 00:00:00 2001 From: zsdonghao Date: Thu, 22 Feb 2018 20:11:48 +0000 Subject: [PATCH 2/3] remove unused import in tfrecord3.py example --- example/tutorial_tfrecord3.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/example/tutorial_tfrecord3.py b/example/tutorial_tfrecord3.py index 0da7a8b83..0d30a029d 100644 --- a/example/tutorial_tfrecord3.py +++ b/example/tutorial_tfrecord3.py @@ -15,15 +15,12 @@ """ -import io import json import os -import time import numpy as np import tensorflow as tf import tensorlayer as tl from PIL import Image -from tensorlayer.layers import set_keep def _int64_feature(value): From 42f34c7890ce63fafc0e842a1a9f3e6b62ff61ec Mon Sep 17 00:00:00 2001 From: zsdonghao Date: Thu, 22 Feb 2018 20:13:34 +0000 Subject: [PATCH 3/3] try Exception in tfrecord3.py --- example/tutorial_tfrecord3.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/tutorial_tfrecord3.py b/example/tutorial_tfrecord3.py index 0d30a029d..b111bf127 100644 --- a/example/tutorial_tfrecord3.py +++ b/example/tutorial_tfrecord3.py @@ -323,7 +323,7 @@ def prefetch_input_data(reader, try: # for TensorFlow 0.11 img = tf.image.resize_images(img, size=(resize_height, resize_width), method=tf.image.ResizeMethod.BILINEAR) -except: +except Exception: # for TensorFlow 0.10 img = tf.image.resize_images(img, new_height=resize_height, new_width=resize_width, method=tf.image.ResizeMethod.BILINEAR) # Crop to final dimensions.