How can I load model both yolov5 and yolov7 - python

When I load yolov5 and yolov7 in python, I get error like this.
Can't get attribute 'MP' on <module 'models.common' from '/workspace/yolov5/models/common.py'>
'MP' is yolov7 attribute...
How can I load yolov7/models/common.py ?
How can I set models.commmon.py python PATH?

create new environment and using this environment download requerments.txt. I think this will work. For example, with anaconda you can use this code to create new environment:
conda create -n name_environment python-3.9
activate this environment:
conda activate name_environment
then download libraries

Related

Using Keras in a Tensorflow Docker Image?

I have a sentiment classifier build with Keras that I want to run using my GPU. As Tensorflows GPU support page recommends, I have installed Docker and downloaded a Tensorflow Docker image.
Now when I try to run my code on one of the Tensorflow Images, I get error codes when trying to import stuff like Keras or Pandas.
I am a bit of a newbie when it comes to Docker but as I understand it, the images simply don't have those libraries installed. So what do I do if I want to use additional besides Tensorflow or whatever else is installed on the image? How do I add these to the image?
Option 1: Add packages to the container:
docker exec <container_name> pip install ...
The downside is that you will have to repeat this every time you recreate the container.
Option 2: Create your own image, using tensorflow image as a base
Create a file named Dockerfile:
FROM tensorflow/tensorflow:latest-gpu-jupyter # change if necessary
RUN pip install ...
# Visit https://docs.docker.com/engine/reference/builder/ for format reference
Then build an image from it:
cd /directory/with/the/Dockerfile
docker build -t my-tf-image .
Then run using your own image:
docker run --gpus all -d -v /some/data:/data my-tf-image
I also recommend using docker-compose for dev environment so that you don't have to remember all these commands. You can create a docker-compose.yml and describe the container using YAML format. Then you can just docker-compose build to build and docker-compose up to run.

Tensorflow 2.4.1 - Couldn't invoke ptxas.exe

I try to run Tensorflow with GPU support (GTX 1660 SUPER).
I created an enviroment using anaconda, than installed cudatoolkit (version 11.0.221) and tensorflow-gpu (version 2.4.1). Afterwards, I downloaded cuDNN (version 8.0.4), and copied all files from cuDNN's bin folder to my environment's bin folder at anaconda3\envs\<env name>\Library\bin.
In my script, I've set the memory limit to my GPU's memory using tf.config.experimental.set_memory_growth.
When I run the script (which uses convolutional algorithms), I get a warning that says Couldn't invoke ptxas.exe --version which comes after an Call to CreateProcess failed. Error code: 2 error.
After the launch failure, I get: Relying on driver to perform ptx compilation. Modify $PATH to customize ptxas location.
I've already tried switching to cuDNN version 8.1.1.
How I fix this?
I got a new fix for this.
First I tried using tensorflow=2.3, cudnn=7.6.5 and cudatoolkit=10.1 as mentioned in previous answers. However, every time I put a model to train, the process was going stale and the training seemed to be stuck in epoch 1.
I then managed to include ptxas in my conda environment by running conda install -c nvidia cuda-nvcc The packages I am using are:
tensorflow=2.9, cudnn=8.1.0, cudatoolkit=11.2.2, cuda-nvcc=11.7.99 and python=3.9
I am running everything on windows 10 flawlessly now.
For the benefit of community adding #Zuk Levinson comment
Solves the issue by using
tensorflow=2.3, cudnn=7.6.5 and cudatoolkit=10.1

which python and tensorflow version is used to train DeepLab v3+ using tensorflow api?

I have been getting multiple errors which are due to conflicts in the TensorFlow version installed in my system and the version used to write the code in Tensorflow API.
I am using python 3.6.7 and Tensorflow 2.0 to get started with the code https://github.com/tensorflow/models/blob/master/research/deeplab/g3doc/installation.md
But I am getting several errors :
flags = tf.app.flags
AttributeError: module 'tensorflow' has no attribute 'app.
As I am using 2.0 , I replaced tf.app.flags with tf.compat.v1.flags.
from tensorflow.contrib import slim as contrib_slim
ModuleNotFoundError: No module named 'tensorflow.contrib'
I am not able to solve the second one.
Can I get help to know which python and tensorflow version should be used to run DeepLab v3+?
You should use the Tensorflow version 1.x to run the DeepLabV3+ model because it uses a session to run and also the slim library which is based on the TensorFlow 1.x. And so your two problems can be solved as:
Do not need to replace tf.app.flags with tf.compat.v1.flags.
To run DeepLabV3+ model, you need to put deeplab and slim folder in a folder (deeplab_slim),
and export them by running following export commands from this parent folder (deeplab_slim):
export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim
export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/deeplab

TensorFlow on Windows 10 with Anaconda & Python 3.6

Let me start by saying I am a beginner on Deep Learning and trying to find my way by following the Tensorflow tutorial, which is mainly applying the inception V3 method to the flowers data set.
https://www.tensorflow.org/tutorials/image_retraining
which includes the following :
cd ~
curl -O (flower data link) -- runs fine
tar xzf flower_photos.tgz --runs fine
bazel build tensorflow/examples/image_retraining:retrain --error: no bazel command found
In order to be able to follow this tutorial, I have also completed the Tensorflow installation tutorial and modified (replaced 35 to 36) it for Python 3.6 compatible whl as follows: pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.2.1-cp36-cp36m-win_amd64.whl
Now back to the main question: After installing the flower data set and installing the bazel package, cygwin64. I went into the Bazel folder and ran the configure file as suggested in the forums as well as touch WORKSPACE and bagel build. When I run the command "bazel build tensorflow/examples/image_retraining:retrain" I still get the error: "Bazel command not found"
I followed similar questions on stackoverflow before openning up my own question, such as: questions- 41791171/bazel-build-for-tensorflow-inception-model and git clone'd the entire Tensorflow folder as instructed but resulted an eror of :bagel: command not found
To summarize, how can I run the Tensorflow Flowerset tutorial and overcome the errors of :bagel: command not found and :bazel: command not found?
It's not mandatory to use Bazel for the TensorFlow Image Retraining tutorial.
You can also run the retrain.py located in the \tensorflow\examples\image_retraining\ folder cloned from the TensorFlow GitHub repo to retrain the Inception v3 model or Mobilenet model.
https://raw.githubusercontent.com/tensorflow/tensorflow/master/tensorflow/examples/image_retraining/retrain.py
Put the Flowers datasets folder (flower_photos) under the image_retraining and run the retrain.py as below:
python retrain.py --image_dir flower_photos
You should see the script will download the Inception v3 model.
The image retraining in progress.
After the retraining is completed, you should see the below:
Copy both output_graph.pb and output_labels.txt in the C:\tmp folder, which are the retrain outputs to the image_retraining folder.
To verify the retrained model, you can run the label_image.py as below.
It should show the top 5 predictions.
python label_image.py --image=flower_photos\daisy\21652746_cc379e0eea_m.jpg --graph=output_graph.pb --labels=output_labels.txt
The expected output should be as below:

Tensorflow Retrain on Windows

When I follow the tutorials of "How to Retrain Inception's Final Layer for New Categories", I need to build the retainer like this
bazel build tensorflow/examples/image_retraining:retrain
However, my tensorflow on windows does not have such directory. I am wondering why and how can I solve the problem?
Thank you in advance
In my case tensorflow version is 1.2 and corresponding retrain.py is here.
Download and extract flowers images from here.
Now run the the retrain.py file as
python retrain.py --image_dir=path\to\dir\where\flowers\images\where\extracted --output_lables=retrained_labels.txt --output_graph=retrained_graph.pb
note: the last two arguments in the above command are optional.
Now to test the retrained model:
go the master branch and download the label_image.py code as shown below
Then run python label_image.py --image=image/path/to/test/classfication --graph=retrained_graph.pb --labels=retrained_labels.txt
The result will be like
From the screenshot, it appears that you have installed the TensorFlow PIP package, whereas the instructions in the image retraining tutorial assume that you have cloned the Git repository (and can use bazel to build TensorFlow).
However, fortunately the script (retrain.py) for image retraining is a simple Python script, which you can download and run without building anything. Simply download the copy of retrain.py from the branch of the TensorFlow repository that matches your installed package (e.g. if you've installed TensorFlow 0.12, you can download this version), and you should be able to run it by typing python retrain.py at the Command Prompt.
I had the same problem on windows. My windows could not find script.retrain. I downloaded retrain.py file from tensoflow website at here. Then, copied the file in the tensorflow folder and run the retrain script using Python command.

Categories

Resources