matterport / Mask_RCNN

Mask R-CNN for object detection and instance segmentation on Keras and TensorFlow
Other
24.69k stars 11.71k forks source link

How to run on GPU? #447

Open AshleyRoth opened 6 years ago

AshleyRoth commented 6 years ago

Hello. Tell me please, how can I run on the GPU? At the moment I can run on video and pictures, but unfortunately only on the CPU .. I have a GPU1080 with 8GB, how can I run it on a GPU? Please tell me Thanks

ljtruong commented 6 years ago

did you install tensorflow with GPU? . it should use GPU by default. pip install tensorflow-gpu

5730279821-TA commented 6 years ago

by default if you install tensorflow-gpu it will automatically run using gpu first to check whether you run on gpu run below code it will show details of gpu or cpu that you run.

from tensorflow.python.client import device_lib print(device_lib.list_local_devices())

AshleyRoth commented 6 years ago

@Worulz @5730279821-TA I use command pip3 install --upgrade tensorflow-gpu from tensorflow site This is where should I prescribe? in the terminal or in the code?

from tensorflow.python.client import device_lib print(device_lib.list_local_devices())

Thanks for your answer

AshleyRoth commented 6 years ago

@Worulz @5730279821-TA tensorflow-gpu is installed, but all the same opens on the CPU. Why can this be so?

Now i check in another PC (in this case notebook).. command results:

print(device_lib.list_local_devices()) 2018-04-15 20:45:31.086775: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:898] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero 2018-04-15 20:45:31.087226: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1344] Found device 0 with properties: name: GeForce GT 740M major: 3 minor: 0 memoryClockRate(GHz): 0.895 pciBusID: 0000:01:00.0 totalMemory: 1.95GiB freeMemory: 1.74GiB 2018-04-15 20:45:31.087255: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1394] Ignoring visible gpu device (device: 0, name: GeForce GT 740M, pci bus id: 0000:01:00.0, compute capability: 3.0) with Cuda compute capability 3.0. The minimum required Cuda capability is 3.5. 2018-04-15 20:45:31.087278: I tensorflow/core/common_runtime/gpu/gpu_device.cc:911] Device interconnect StreamExecutor with strength 1 edge matrix: 2018-04-15 20:45:31.087291: I tensorflow/core/common_runtime/gpu/gpu_device.cc:917] 0 2018-04-15 20:45:31.087306: I tensorflow/core/common_runtime/gpu/gpu_device.cc:930] 0: N [name: "/device:CPU:0" device_type: "CPU" memory_limit: 268435456 locality {

what's the problem???? Please help

5730279821-TA commented 6 years ago

@AshleyRoth Did you have the code that limit number of your gpu like " CUDA_VISIBLE_DEVICES=0 " ?

fastlater commented 6 years ago

as @5730279821-TA , you can add these lines:

import os
os.environ['CUDA_VISIBLE_DEVICES'] = '0'
AshleyRoth commented 6 years ago

@5730279821-TA @fastlater

I used from here visualization_cv.py https://github.com/markjay4k/Mask-RCNN-series/blob/master/visualize_cv.py for working with camera.

He seems to have nothing in the code about the GPU. I want to run the camera to start, unfortunately this is the only example I found. Each time it is launched only on the CPU ... (I need something to import about the GPU? can not understand...

thanks

fastlater commented 6 years ago

I guess your problem is TF. Did you tried with a different script? just for testing if your tensorflow is really using your gpu? Something like:

import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))

As @Worulz said, it should use GPU by default.

AshleyRoth commented 6 years ago

@Worulz @fastlater fixed bugs, it was necessary to install version 1.3. Another problem now, when I run video using a script "visualization_cv.py https://github.com/markjay4k/Mask-RCNN-series/blob/master/visualize_cv.py", uses 97% of the entire video memory (8GB in total). How can I fix this? So that much does not use video memory

Zumbalamambo commented 6 years ago

@AshleyRoth use cython to speedup

AshleyRoth commented 6 years ago

@Zumbalamambo could not explain in detail how to do this, please? Thank you

ljtruong commented 6 years ago

@AshleyRoth you can limit the gpu memory using the code below. Add it to the script which you are invoking. Keeping in mind you must allocate enough for the model used.

import tensorflow as tf
from keras.backend.tensorflow_backend import set_session
config = tf.ConfigProto()
config.gpu_options.per_process_gpu_memory_fraction = 0.3
set_session(tf.Session(config=config))

source: https://github.com/keras-team/keras/issues/1538

harshil014 commented 6 years ago

Which cudnn and cuda version is required for setting up this repo for training?

ljtruong commented 6 years ago

@harshil014 I was able to use the latest cuda version that tensorflow supports.

Shreeyak commented 6 years ago

@Worulz Were you able to use CUDA 9? I'm assuming that you're using tensorflow 1.8 or greater?

ljtruong commented 6 years ago

@Shreeyak yes.

Shreeyak commented 6 years ago

Thank you. I am facing some weird error regarding imgaug. This eliminates one cause. May I ask which python version you are using?

ljtruong commented 6 years ago

python 3.6. I'm using it in virtualenv

123Vyacheslav123 commented 6 years ago

Hello. Anybody decided problems with run on GPU? I try run train_shapes.ipnb with parameters: GPU_COUNT = 1 IMAGES_PER_GPU =1 but training process all the same using only CPU!! How fix it ? Thanks.

lackBfun commented 5 years ago

Hello. Anybody decided problems with run on GPU? I try run train_shapes.ipnb with parameters: GPU_COUNT = 1 IMAGES_PER_GPU =1 but training process all the same using only CPU!! How fix it ? Thanks.

I got the same problem, anyone knows how to fix it? Thx

jimxie2012 commented 5 years ago

issue:+1, I'm facing same problem. tf: 1.12.2 (with gpu) cuda: 9.0 cudnn: 7.3.1 keras: 2.1.3 GPU: tesla k40m

kaanaykutkabakci commented 5 years ago

I have solved the problem by installing tensorflow-gpu==1.6.0 and keras==2.2.0 with Cuda 10.

When I tried tensorflow-gpu==1.9.0, I noticed that the training started but did not continue.

subbulakshmisubha commented 5 years ago

@kaanaykutkabakci i am trying to get mask rcnn training running on my gpu. So just to be sure the configuration you have installed is tensorflow 1.3 and keras 2.0.8 and tensorflow-gpu as 1.9.0 for Cuda 10?

kaanaykutkabakci commented 5 years ago

@kaanaykutkabakci i am trying to get mask rcnn training running on my gpu. So just to be sure the configuration you have installed is tensorflow 1.3 and keras 2.0.8 and tensorflow-gpu as 1.9.0 for Cuda 10?

Hello @subbulakshmisubha . I have installed tensorflow-gpu==1.6.0 and keras 2.2.0 with Cuda 10. This configuration is working without any problem.

subbulakshmisubha commented 5 years ago

@kaanaykutkabakci thanks. What about the TensorFlow version? I have installed tensorflow gpu as per what you mentioned but what should be the TensorFlow version?

kaanaykutkabakci commented 5 years ago

@kaanaykutkabakci thanks. What about the TensorFlow version? I have installed tensorflow gpu as per what you mentioned but what should be the TensorFlow version?

@subbulakshmisubha hello. I don't want to mislead you, but as far as I know you don't need to install tensorflow after installing tensorflow-gpu.

amy-tabb commented 4 years ago

I've gotten a consistent method to install a fresh environment with conda and training (with GPU) for the balloon sample. I am new to Python (C++ expert). I forget exactly how I got this environment installed initially. Create a new environment by

conda create --name <env-name> --file working-gpu.txt python3 setup.py install

working-gpu.txt file is attached, I'm on Ubuntu 18.04.

working-gpu.txt

LucienZhang commented 4 years ago

based on the record from @amy-tabb , tensorflow-gpu=1.14.0 + keras=2.2.4 finally work for me. I'm using Ubuntu 16.04.

jyothir07 commented 4 years ago

@harshil014 I was able to use the latest cuda version that tensorflow supports.

could u please explain how u made it work. which versions of tf-gpu, keras for windows

nikola-t commented 4 years ago

i solved my problem: conda install -c anaconda tensorflow-gpu=1.14.0 (i have mega mess in system) :-)

Akshay-Ijantkar commented 4 years ago

@nikola-t can you please tell me which Python version, tensorflow-gpu version, keras version, CUDA version you are using? I had a sleepless night honestly in searching right versions to make MAsk rcnn work in my system?

nikola-t commented 4 years ago

@nikola-t can you please tell me which Python version, tensorflow-gpu version, keras version, CUDA version you are using? I had a sleepless night honestly in searching right versions to make MAsk rcnn work in my system?

Python 3.6.10 Tensorflow 1.9.0 (updated today) Keras 2.10 Cuda 10.0 (downgraded today)

I have env. for Mask RCNN conda create --name mask python=3 conda activate mask

i had problem with coco, solved on this way: first install cython, then: git clone https://github.com/pdollar/coco.git cd coco/PythonAPI make sudo make install sudo python setup.py install

i downgraded from cuda 10.1 to cuda 10.0: https://gist.github.com/bogdan-kulynych/f64eb148eeef9696c70d485a76e42c3a

niniack commented 4 years ago

I've gotten a consistent method to install a fresh environment with conda and training (with GPU) for the balloon sample. I am new to Python (C++ expert). I forget exactly how I got this environment installed initially. Create a new environment by

conda create --name <env-name> --file working-gpu.txt python3 setup.py install

working-gpu.txt file is attached, I'm on Ubuntu 18.04.

working-gpu.txt

To anyone seeing this later (and this is probably very trivial) :

If you are having trouble running the command because of ParseError: Could not parse explicit, just update your conda version to latest one, they fixed that bug there

Also don't forget to activate your conda environment after you create it! You want to run the setup script inside the env

Naveennavik commented 4 years ago

I have windows 10 tensorflow and tensorflow_gpu are 2.2.0 and keras 2.3.1 but code is running only on cpu what is the issue?

kaanaykutkabakci commented 4 years ago

I have windows 10 tensorflow and tensorflow_gpu are 2.2.0 and keras 2.3.1 but code is running only on cpu what is the issue?

You need to install CUDA that is compatible with your GPU. Then, download cuDNN library and copy them to the relevant files in CUDA.

Naveennavik commented 4 years ago

when i type nvc--version it gives nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2018 NVIDIA Corporation Built on Sat_Aug_25_21:08:04_Central_Daylight_Time_2018 Cuda compilation tools, release 10.0, V10.0.130 how to download cuDNN library and copy them to the relevant files? @kaanaykutkabakci

kaanaykutkabakci commented 4 years ago

when i type nvc--version it gives nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2018 NVIDIA Corporation Built on Sat_Aug_25_21:08:04_Central_Daylight_Time_2018 Cuda compilation tools, release 10.0, V10.0.130 how to download cuDNN library and copy them to the relevant files? @kaanaykutkabakci

https://developer.nvidia.com/cudnn

Google search: https://www.youtube.com/watch?v=2TcnIzJ1RQs

Behnam72 commented 2 years ago

As @Worulz said, it should use GPU by default.

and how can you tell it's running on GPU? I got this:

/home/behnamazmoon/.local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:516: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. _np_qint8 = np.dtype([("qint8", np.int8, 1)]) /home/behnamazmoon/.local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:517: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. _np_quint8 = np.dtype([("quint8", np.uint8, 1)]) /home/behnamazmoon/.local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:518: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. _np_qint16 = np.dtype([("qint16", np.int16, 1)]) /home/behnamazmoon/.local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:519: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. _np_quint16 = np.dtype([("quint16", np.uint16, 1)]) /home/behnamazmoon/.local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:520: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. _np_qint32 = np.dtype([("qint32", np.int32, 1)]) /home/behnamazmoon/.local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:525: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. np_resource = np.dtype([("resource", np.ubyte, 1)]) /home/behnamazmoon/.local/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:541: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. _np_qint8 = np.dtype([("qint8", np.int8, 1)]) /home/behnamazmoon/.local/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:542: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. _np_quint8 = np.dtype([("quint8", np.uint8, 1)]) /home/behnamazmoon/.local/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:543: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. _np_qint16 = np.dtype([("qint16", np.int16, 1)]) /home/behnamazmoon/.local/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:544: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. _np_quint16 = np.dtype([("quint16", np.uint16, 1)]) /home/behnamazmoon/.local/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:545: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. _np_qint32 = np.dtype([("qint32", np.int32, 1)]) /home/behnamazmoon/.local/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:550: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. np_resource = np.dtype([("resource", np.ubyte, 1)]) b'Hello, TensorFlow!'

Behnam72 commented 2 years ago

This solution installs python 3.7 but mrcnn module uses 3.6 You can use this command if you have anaconda installed:

conda create --name mrcnnGPU python=3.6 tensorflow-gpu==1.14.0 keras==2.2.4 opencv imgaug tqdm imagecodecs pandas hdf5 h5py jupyter notebook

keras==2.1.0 works as well, but there are fewer warnings with 2.2.4

ametal commented 2 years ago

I've gotten a consistent method to install a fresh environment with conda and training (with GPU) for the balloon sample. I am new to Python (C++ expert). I forget exactly how I got this environment installed initially. Create a new environment by

conda create --name <env-name> --file working-gpu.txt python3 setup.py install

working-gpu.txt file is attached, I'm on Ubuntu 18.04.

working-gpu.txt

Thank you for save my day run on python3.6

IdentifyResearchAreasandGoals commented 2 years ago

GPU is not work in mask RCNN

My enviroment is windows NVIDIA GeForce RTX3050LaptopGPU • Step 1: I create Mask_RCNN environment python version is 3.6  conda create -n Mask_RCNN python=3.6 • Step 2:Clone the repository. First, we will clone the mask rcnn repository which has the architecture for Mask R-CNN Download mrcnn folder from this repository: https://github.com/matterport/Mask_RCNN • Step 3: Install the dependencies  pip install tensorflow-gpu==1.15.0  pip install keras==2.2.5  pip install numpy  pip install scipy  pip install Pillow  pip install cython  pip install matplotlib  pip install scikit-image  pip install opencv-python  pip install h5py==2.10.0  pip install IPython[all]  python setup.py install • Step 4: Download the pre-trained weights (trained on MS COCO) ...  Download coco weights : https://github.com/matterport/Mask_RC. • Step 5: Create folder : Dataset  3- Create dataset folder. Under dataset folder -> Create 2 folders "train" and "val".  4- Put training images in train folder.  5- Put validation images in val folder  6- Use VGGAnnotator tool for Annotations.

huseyinbozkurtt commented 10 months ago

GPU is not work in mask RCNN

My enviroment is windows NVIDIA GeForce RTX3050LaptopGPU • Step 1: I create Mask_RCNN environment python version is 3.6  conda create -n Mask_RCNN python=3.6 • Step 2:Clone the repository. First, we will clone the mask rcnn repository which has the architecture for Mask R-CNN Download mrcnn folder from this repository: https://github.com/matterport/Mask_RCNN • Step 3: Install the dependencies  pip install tensorflow-gpu==1.15.0  pip install keras==2.2.5  pip install numpy  pip install scipy  pip install Pillow  pip install cython  pip install matplotlib  pip install scikit-image  pip install opencv-python  pip install h5py==2.10.0  pip install IPython[all]  python setup.py install • Step 4: Download the pre-trained weights (trained on MS COCO) ...  Download coco weights : https://github.com/matterport/Mask_RC. • Step 5: Create folder : Dataset  3- Create dataset folder. Under dataset folder -> Create 2 folders "train" and "val".  4- Put training images in train folder.  5- Put validation images in val folder  6- Use VGGAnnotator tool for Annotations.

I do each step the same way, but it does not create masking.My enviroment is windows 10 NVIDIA GeForce RTX3060LaptopGPU.Why could it be ?