From 6681a02ab8b195dfb1b0bdc15143719cca8047ea Mon Sep 17 00:00:00 2001 From: belotfa <59921445+belotfa@users.noreply.github.com> Date: Wed, 15 Jan 2020 14:31:21 +0100 Subject: [PATCH 1/5] Remove useless global variable in custom_utils Removing this variable allows to use dfferent instances of the same class (CustomImagePrediction) at the same time without using the same model_json. --- imageai/Prediction/Custom/custom_utils.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/imageai/Prediction/Custom/custom_utils.py b/imageai/Prediction/Custom/custom_utils.py index 8dcea8d8..69bc977d 100644 --- a/imageai/Prediction/Custom/custom_utils.py +++ b/imageai/Prediction/Custom/custom_utils.py @@ -1,8 +1,5 @@ import json -CLASS_INDEX = None - - def preprocess_input(x): """Preprocesses a tensor encoding a batch of images. @@ -22,13 +19,9 @@ def preprocess_input(x): return x -def decode_predictions(preds, top=5, model_json=""): - - - global CLASS_INDEX +def decode_predictions(preds, top=5, model_json): - if CLASS_INDEX is None: - CLASS_INDEX = json.load(open(model_json)) + CLASS_INDEX = json.load(open(model_json)) results = [] for pred in preds: top_indices = pred.argsort()[-top:][::-1] @@ -38,4 +31,4 @@ def decode_predictions(preds, top=5, model_json=""): each_result.append(pred[i]) results.append(each_result) - return results \ No newline at end of file + return results From c14b135a544c16a76ee0c745fb5cc47a05c37109 Mon Sep 17 00:00:00 2001 From: belotfa <59921445+belotfa@users.noreply.github.com> Date: Wed, 15 Jan 2020 16:25:00 +0100 Subject: [PATCH 2/5] Modify arguments --- imageai/Prediction/Custom/custom_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imageai/Prediction/Custom/custom_utils.py b/imageai/Prediction/Custom/custom_utils.py index 69bc977d..a0548509 100644 --- a/imageai/Prediction/Custom/custom_utils.py +++ b/imageai/Prediction/Custom/custom_utils.py @@ -19,7 +19,7 @@ def preprocess_input(x): return x -def decode_predictions(preds, top=5, model_json): +def decode_predictions(preds, top=5, model_json=""): CLASS_INDEX = json.load(open(model_json)) results = [] From 42f8f1f1e44697b47c509319692d0b94a29f249f Mon Sep 17 00:00:00 2001 From: belotfa <59921445+belotfa@users.noreply.github.com> Date: Thu, 16 Jan 2020 09:30:14 +0100 Subject: [PATCH 3/5] Update requirements.txt --- requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index ca4c3d44..b124fb60 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ -tensorflow -keras +tensorflow==1.14 +keras==2.3 numpy pillow scipy From 73a703b17698a91d8567d3185bddc25217eedcd1 Mon Sep 17 00:00:00 2001 From: belotfa <59921445+belotfa@users.noreply.github.com> Date: Wed, 22 Jan 2020 13:45:51 +0100 Subject: [PATCH 4/5] Update requirements to downgrade Pillow version. --- requirements.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/requirements.txt b/requirements.txt index b124fb60..2a7cd942 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ -tensorflow==1.14 -keras==2.3 +tensorflow +keras numpy -pillow +pillow<7.0.0 scipy h5py matplotlib From 54c7aceb6e909f876e3ec2261ad337deb26be4ce Mon Sep 17 00:00:00 2001 From: belotfa <59921445+belotfa@users.noreply.github.com> Date: Sat, 8 Feb 2020 17:16:49 +0100 Subject: [PATCH 5/5] Update custom_utils.py --- imageai/Prediction/Custom/custom_utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/imageai/Prediction/Custom/custom_utils.py b/imageai/Prediction/Custom/custom_utils.py index a0548509..7f59d0bb 100644 --- a/imageai/Prediction/Custom/custom_utils.py +++ b/imageai/Prediction/Custom/custom_utils.py @@ -21,7 +21,8 @@ def preprocess_input(x): def decode_predictions(preds, top=5, model_json=""): - CLASS_INDEX = json.load(open(model_json)) + with open(model_json) as f: + CLASS_INDEX = json.load(f) results = [] for pred in preds: top_indices = pred.argsort()[-top:][::-1]