diff --git a/imageai/Prediction/Custom/custom_utils.py b/imageai/Prediction/Custom/custom_utils.py index 8dcea8d8..7f59d0bb 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. @@ -24,11 +21,8 @@ def preprocess_input(x): def decode_predictions(preds, top=5, model_json=""): - - global CLASS_INDEX - - if CLASS_INDEX is None: - 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] @@ -38,4 +32,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 diff --git a/requirements.txt b/requirements.txt index ca4c3d44..2a7cd942 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ tensorflow keras numpy -pillow +pillow<7.0.0 scipy h5py matplotlib