Search code examples
dockertensorflowjupyter-notebookobject-detection-api

I installed a TensorFlow API (Object Detection) locally using Docker. How can I use this package in a Jupyter Notebook?


I am trying to use Tensorflow's Object Detection library for a student project. I followed the Tensorflow team's instructions for installing locally on Docker (See these links: Tensorflow Team's Instructions and Medium Article with the Same Instructions). I was able to get the image up and running successfully on Docker, i.e. I successfully installed the API.

But I am lacking the background information on Docker to know how and where I can import and use Object Detection functions (ex: from object_detection.utils import label_map_util,from object_detection.utils import dataset_util etc.)

  1. When I try in my local Anaconda Jupyter Notebook, I get a ModuleNotFound Error, presumably because the object_detection API is located in the Docker Container.
  2. I tried using Docker to open a separate Jupyter Notebook by following this article. Here is what I typed into Powershell (command prompt), under the models/research folder: $ docker run -p 8888:8888 -v $(pwd):/home/jovyan/work jupyter/minimal-notebook. I was able to open a separate Jupyter Notebook using Docker, but this created an entirely separate container from the one with object_detection installed in it. So this also returned a ModuleNotFound error.
  3. I tried to run the same command in a bash shell in the correct container (I used docker exec -it [container_name] /bin/bash). However when I try to enter any 'docker' or 'sudo' command in that bash shell it returns an error generally saying those commands are not found in the bash shell.

I think I just do not have enough knowledge of Docker to know how and where I am able to import object_detection into my Python code. Any resources, links, or tips will be appreciated.


Solution

  • After a few more attempts, I have an answer for those who may be struggling with a similar problem after installing a module using Docker. I believe through the course of solving this problem I was encountering at least one of the following two problems:

    1. Wrong environment: I was coding in a Jupyter Notebook located on the base in Anaconda. For tensorflow or APIs depending on tensorflow, you have to utilize the "Applications on:" dropbox in the Anaconda Navigator and switch to the tensorflow (tf) environment. I believed I had this environment selected for most of the troubleshooting but sometimes between restarts and installs something got mixed up, so check on this.

    2. System Environment Variables need to be manually updated: This was the most important and most complicated problem that was stifling me from being able to import object_detection. Python uses system paths to search for modules, but sometimes a module may be in a directory not included in the "Path" environment variable. I changed my environment variables according to the solution posted here. The only thing you need go be careful with is the name of the Python folder. This depends on the name of your Python program file. My Python folder was called "Python", not "Python36". But regardless, kudos to the collaborators on the aforementioned solution because it really helped me out.