Uncategorized

How can I adapt my python code to install the latest tensorflow object detection package


I have been following this and have gotten around to the training and detection part of the video. However, I encountered some issues in the installation of various different libraries including tensorflow and matplotlib.

The main error was always the same: Result of doing "pip install tensorflow" in my cmd.

ERROR: pip’s dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.

I also got a bunch of warnings before it tried to install anything: Warnings accompanied with "pip install tensorflow"

DEPRECATION: Loading egg at c:\users\aadi\onedrive\desktop\tfodcourse\tfod\lib\site-packages\apache_beam-2.53.0-py3.11-win-amd64.egg is deprecated. pip 24.3 will enforce this behaviour change. A possible replacement is to use pip for package installation.. Discussion can be found at https://github.com/pypa/pip/issues/12330

I tried the github link it led me to, but the link didn’t mention any solutions to my problem. I also tried browsing different forums and getting help from more experienced people but they had no idea either. It is important to note that this error only occurs when I am inside the virtual environment. I was able to uninstall and reinstall tensorflow perfectly fine when I was not inside the venv.

After researching online, I found out that the tensorflow research model that I am using in my code is deprecated and that I should be using something along the lines of this.

My original code looked like this:

# Install Tensorflow Object Detection 
from setuptools import find_packages
from setuptools import setup

if os.name=='posix':  
    !apt-get install protobuf-compiler
    !cd Tensorflow/models/research && protoc object_detection/protos/*.proto --python_out=. && cp object_detection/packages/tf2/setup.py . && python -m pip install . 
    
if os.name=='nt':
    url="https://github.com/protocolbuffers/protobuf/releases/download/v3.15.6/protoc-3.15.6-win64.zip"
    wget.download(url)
    !move protoc-3.15.6-win64.zip {paths['PROTOC_PATH']}
    !cd {paths['PROTOC_PATH']} && tar -xf protoc-3.15.6-win64.zip
    os.environ['PATH'] += os.pathsep + os.path.abspath(os.path.join(paths['PROTOC_PATH'], 'bin'))   
    !cd Tensorflow/models/blob && protoc object_detection/protos/*.proto --python_out=. && copy object_detection\\packages\\tf2\\setup.py setup.py && python setup.py build && python setup.py install



    REQUIRED_PACKAGES = [
        # Required for apache-beam with PY3
        'avro-python3',
        'apache-beam',
        'pillow',
        'lxml',
        'matplotlib',
        'Cython',
        'contextlib2',
        'tf-slim',
        'six',
        'pycocotools',
        'lvis',
        'scipy',
        'pandas',
        'tf-models-official>=2.5.1',
        'tensorflow_io',
        'keras',
        'pyparsing==2.4.7',  # TODO(b/204103388)
        'sacrebleu<=2.2.0'  # https://github.com/mjpost/sacrebleu/issues/209
    ]

    setup(
        name="object_detection",
        version='0.1',
        install_requires=REQUIRED_PACKAGES,
        include_package_data=True,
        packages=(
            [p for p in find_packages() if p.startswith('object_detection')] +
            find_packages(where=os.path.join('.', 'slim'))),
        package_dir={
            'datasets': os.path.join('slim', 'datasets'),
            'nets': os.path.join('slim', 'nets'),
            'preprocessing': os.path.join('slim', 'preprocessing'),
            'deployment': os.path.join('slim', 'deployment'),
            'scripts': os.path.join('slim', 'scripts'),
        },
        description='Tensorflow Object Detection Library',
        python_requires=">3.6",
    )
    
    !cd Tensorflow/models/research/slim && pip install -e . 

Modules such as wget and the other prerequisites were able to be included successfully.

How can I adapt this code to better match the more recent tensorflow updates?



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *