jackliu333 / object_detection_using_tensorflow

9 stars 2 forks source link

Running into import issue when trying to run trained model #1

Closed Djoels closed 1 year ago

Djoels commented 2 years ago

Upon trying to run the notebook in Google Colab, I stumble upon an error when trying to run the trained model (last step).

The error trace:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
[<ipython-input-26-face25ec5cb2>](https://localhost:8080/#) in <module>
      3 from object_detection.utils import label_map_util
      4 from object_detection.utils import visualization_utils as viz_utils
----> 5 from object_detection.builders import model_builder
      6 from object_detection.utils import config_util
      7 

10 frames
[/usr/local/lib/python3.7/dist-packages/keras/api/_v1/keras/__internal__/layers/__init__.py](https://localhost:8080/#) in <module>
      7 
      8 from keras.engine.base_layer import BaseRandomLayer
----> 9 from keras.layers.preprocessing.image_preprocessing import BaseImageAugmentationLayer
     10 from tensorflow.python.util import module_wrapper as _module_wrapper
     11 

ImportError: cannot import name 'BaseImageAugmentationLayer' from 'keras.layers.preprocessing.image_preprocessing' (/usr/local/lib/python3.7/dist-packages/keras/layers/preprocessing/image_preprocessing.py)

It seems like a version mismatch between object detection API and keras?

Note: other than having to install a different libcudnn8 version as detailed here (same issue as mentioned in that SO): https://stackoverflow.com/questions/70998639/dnn-library-is-not-found-ssd-mobile-net-v2-in-colab and running the evaluation command, I didn't do anything different from original notebook

The package versions as reported in installation step: Successfully installed apache-beam-2.41.0 avro-python3-1.10.2 cloudpickle-2.2.0 colorama-0.4.5 dill-0.3.1.1 docopt-0.6.2 fastavro-1.6.1 flatbuffers-1.12 gast-0.4.0 hdfs-2.7.0 keras-2.9.0 lvis-0.5.3 object-detection-0.1 orjson-3.8.0 portalocker-2.5.1 proto-plus-1.22.1 protobuf-3.19.5 py-cpuinfo-8.0.0 pymongo-3.12.3 pyparsing-2.4.7 pyyaml-5.4.1 requests-2.28.1 sacrebleu-2.2.0 sentencepiece-0.1.97 seqeval-1.2.2 tensorboard-2.9.1 tensorflow-2.9.2 tensorflow-addons-0.17.1 tensorflow-estimator-2.9.0 tensorflow-io-0.27.0 tensorflow-io-gcs-filesystem-0.27.0 tensorflow-model-optimization-0.7.3 tensorflow-text-2.9.0 tf-models-official-2.9.2 tf-slim-1.1.0

jackliu333 commented 2 years ago

It looks to be that the object detection module is not installed properly. I have refreshed the notebook, see if it works now.

Djoels commented 2 years ago

the repo doesn't show any changes? is this the notebook you refreshed? https://colab.research.google.com/github/jackliu333/object_detection_using_tensorflow/blob/main/Training_Customised_Image_Detection_Model.ipynb when trying to run it I stumble upon the exact same issue as before

jackliu333 commented 2 years ago

See https://github.com/jackliu333/object_detection_using_tensorflow/blob/main/FoodBank_Training_Customised_Image_Detection_Model_v2.ipynb

I switched to TF2.9 along with cuda version due to compatibility issue in colab.

Djoels commented 2 years ago

aha, in that version it seems to work now! thanks a lot! Note: I had to update the model training bit so that the checkpoint was different and the training steps I lowered as well (to get faster feedback)

training_steps = 1000
check_point = 'ckpt-1' # ckpt-31 didn't exist in my environment