While implementing "layoutparser" I get this error. What is wrong with this?
model = lp.Detectron2LayoutModel('lp://PubLayNet/mask_rcnn_X_101_32x8d_FPN_3x/config',
extra_config=["MODEL.ROI_HEADS.SCORE_THRESH_TEST", 0.5],
label_map={0: "Text", 1: "Title", 2: "List", 3:"Table", 4:"Figure"})
AttributeError Traceback (most recent call last)
<ipython-input-8-d8a245fa8739> in <module>()
----> 1 model = lp.Detectron2LayoutModel('lp://PubLayNet/mask_rcnn_X_101_32x8d_FPN_3x/config',
2 extra_config=["MODEL.ROI_HEADS.SCORE_THRESH_TEST", 0.5],
3 label_map={0: "Text", 1: "Title", 2: "List", 3:"Table", 4:"Figure"}) 34 frames /usr/local/lib/python3.7/dist-packages/PIL/Image.py in
__getattr__(name)
63 stacklevel=2,
64 )
---> 65 return categories[name]
66 elif name in ("NEAREST", "NONE"):
67 warnings.warn( AttributeError: module 'PIL.Image' has no attribute 'Resampling'
Convert image to numpy array.
import numpy as np
image = np.asarray(image)
model.detect(image)
If you are using Colab tool then this error might occur if your code is using GPU but your Colab is configured with CPU version.
Runtime --> Change Runtime Type --> Select "GPU"
Related
I am new to deeplearning.
I am trying to use the deepface library in my local machine. I used pip install deepface to install the library, tried on python 3.7.13, 3.8.13 and 3.9.13 which were all created using conda virtual environment.
However when running the code snippet below, I am getting the same error when running on my local machine. Do I need a GPU to run the library? If yes, how do I set it up? Because from the online guides/ articles, none of them mentioned the need of installing / setup a GPU.
I have a GeForce MX450 on my local pc.
code
import cv2
from deepface import DeepFace
import numpy as np
def analyse_face():
imagepath = "happy_face_woman.png"
image = cv2.imread(imagepath)
face_analysis = DeepFace.analyze(image)
print(face_analysis)
print(analyse_face())
Error:
ResourceExhaustedError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_14196\3829791526.py in <module>
12 print(face_analysis)
13
---> 14 analyse_face()
~\AppData\Local\Temp\ipykernel_14196\3829791526.py in analyse_face()
9 imagepath = "happy_face_woman.png"
10 image = cv2.imread(imagepath)
---> 11 face_analysis = DeepFace.analyze(image)
12 print(face_analysis)
13
c:\Users\user_name\anaconda3\envs\deepFacepy37\lib\site-packages\deepface\DeepFace.py in analyze(img_path, actions, models, enforce_detection, detector_backend, prog_bar)
352
353 if 'age' in actions and 'age' not in built_models:
--> 354 models['age'] = build_model('Age')
355
356 if 'gender' in actions and 'gender' not in built_models:
c:\Users\user_name\anaconda3\envs\deepFacepy37\lib\site-packages\deepface\DeepFace.py in build_model(model_name)
61 model = models.get(model_name)
62 if model:
---> 63 model = model()
...
-> 1922 seed=self.make_legacy_seed())
1923
1924 def truncated_normal(self, shape, mean=0., stddev=1., dtype=None):
ResourceExhaustedError: failed to allocate memory [Op:AddV2]
Different Error output
ResourceExhaustedError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_14196\3829791526.py in <module>
12 print(face_analysis)
13
---> 14 analyse_face()
~\AppData\Local\Temp\ipykernel_14196\3829791526.py in analyse_face()
9 imagepath = "happy_face_woman.png"
10 image = cv2.imread(imagepath)
---> 11 face_analysis = DeepFace.analyze(image)
12 print(face_analysis)
13
c:\Users\user_name\anaconda3\envs\deepFacepy37\lib\site-packages\deepface\DeepFace.py in analyze(img_path, actions, models, enforce_detection, detector_backend, prog_bar)
352
353 if 'age' in actions and 'age' not in built_models:
--> 354 models['age'] = build_model('Age')
355
356 if 'gender' in actions and 'gender' not in built_models:
c:\Users\user_name\anaconda3\envs\deepFacepy37\lib\site-packages\deepface\DeepFace.py in build_model(model_name)
61 model = models.get(model_name)
62 if model:
---> 63 model = model()
...
-> 1922 seed=self.make_legacy_seed())
1923
1924 def truncated_normal(self, shape, mean=0., stddev=1., dtype=None):
ResourceExhaustedError: OOM when allocating tensor with shape[7,7,512,4096] and type float on /job:localhost/replica:0/task:0/device:GPU:0 by allocator GPU_0_bfc [Op:RandomUniform]
Additional Info
I've ran the command to check my GPU usage and the details is as follows:
!nvidia-smi
Why do not you disable GPU?
import os
os.environ["CUDA_VISIBLE_DEVICES"]=""
I am using Jupyter from Anaconda and trying to import a shapefile with following command line:
import geopandas as gpd
gdf = gpd.read_file('C:\Downloads\Temp\shapefile\regions.shp')
print (gdf)
gdf.plot()
However, I got following errors:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
Input In [7], in <cell line: 1>()
----> 1 gdf = gpd.read_file('C:\Downloads\Temp\shapefile\regions.shp')
2 print (gdf)
3 gdf.plot()
File C:\Anaconda3\lib\site-packages\geopandas\io\file.py:166, in _read_file(filename, bbox, mask, rows, **kwargs)
104 def _read_file(filename, bbox=None, mask=None, rows=None, **kwargs):
105 """
106 Returns a GeoDataFrame from a file or URL.
107
(...)
164 by using the encoding keyword parameter, e.g. ``encoding='utf-8'``.
165 """
--> 166 _check_fiona("'read_file' function")
167 filename = _expand_user(filename)
169 if _is_url(filename):
File C:\Anaconda3\lib\site-packages\geopandas\io\file.py:80, in _check_fiona(func)
78 def _check_fiona(func):
79 if fiona is None:
---> 80 raise ImportError(
81 f"the {func} requires the 'fiona' package, but it is not installed or does "
82 f"not import correctly.\nImporting fiona resulted in: {fiona_import_error}"
83 )
ImportError: the 'read_file' function requires the 'fiona' package, but it is not installed or does not import correctly.
Importing fiona resulted in: DLL load failed while importing ogrext: The specified module could not be found.
I have geopanda installed and not sure what is the problem.
Trying to run ImageAI in Jupyter.
I'm getting the following error
Using TensorFlow backend.
AttributeError Traceback (most recent call last)
in
----> 1 from imageai.Detection.Custom import DetectionModelTrainer
~\anaconda3\envs\ImageAI\lib\site-packages\imageai\Detection\Custom_init_.py in
19 import cv2
20
---> 21 tf.config.run_functions_eagerly(True)
22 os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3"
23
~\anaconda3\envs\ImageAI\lib\site-packages\tensorflow_core\python\util\module_wrapper.py in getattr(self, name)
191 def getattr(self, name):
192 try:
--> 193 attr = getattr(self._tfmw_wrapped_module, name)
194 except AttributeError:
195 if not self._tfmw_public_apis:
AttributeError: module 'tensorflow._api.v1.config' has no attribute 'run_functions_eagerly
What is the issue here?
Thanks in advance
You can try like this:
import tensorflow.compat.v1 as tf
tf.config.experimental_run_functions_eagerly(True)
#tf.function
def fn():
# `enter code here
I am trying to run the image segmentation tutorial from tensorflow.
i am getting this error in the line
from tensorflow_examples.models.pix2pix import pix2pix
The comeplete error is following
AttributeError Traceback (most recent call last)
<ipython-input-3-bfebd9cf4be1> in <module>()
----> 1 from tensorflow_examples.models.pix2pix import pix2pix
2
3 import tensorflow_datasets as tfds
4 tfds.disable_progress_bar()
5
~\Anaconda3\lib\site-packages\tensorflow_examples\models\pix2pix\pix2pix.py in <module>()
37 IMG_WIDTH = 256
38 IMG_HEIGHT = 256
---> 39 AUTOTUNE = tf.data.experimental.AUTOTUNE
40
41
AttributeError: module 'tensorflow.data' has no attribute 'experimental'
I'm trying to train my custom dataset by creating yolov3.cfg file and yolov3.weights file with labelled annotations and images using darkflow. However when I'm trying to run tfnet = TFNet(history), it throws an error of "exit not defined".
I have installed darkflow by the following steps:
In Anaconda Prompt:
git clone https://github.com/thtrieu/darkflow.git
cd darkflow
python3 setup.py build_ext –inplace
pip install
then:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import cv2
from darkflow.net.build import TFNet
history = {"model": "C:/Users/Business Intelli/Desktop/Object-Detection/Dataset/yolov3.cfg",
"load": "C:/Users/Business Intelli/Desktop/Object-Detection/Dataset/yolov3.weights",
"batch": 8,
"epoch": 50,
"gpu": 1.0,
"train": True,
"annotation": "C:/Users/Business Intelli/Desktop/Object-Detection/Dataser/Stumps",
"dataset": "C:/Users/Business Intelli/Desktop/Object-Detection/Dataser/Stumps"}
tfnet = TFNet(history)
Parsing C:/Users/Business Intelli/Desktop/Object-Detection/Dataset/yolov3.cfg
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-10-6f6b945047c5> in <module>
----> 1 tfnet = TFNet(history)
~\Anaconda3\lib\site-packages\darkflow\net\build.py in __init__(self, FLAGS, darknet)
56
57 if darknet is None:
---> 58 darknet = Darknet(FLAGS)
59 self.ntrain = len(darknet.layers)
60
~\Anaconda3\lib\site-packages\darkflow\dark\darknet.py in __init__(self, FLAGS)
15
16 print('Parsing {}'.format(self.src_cfg))
---> 17 src_parsed = self.parse_cfg(self.src_cfg, FLAGS)
18 self.src_meta, self.src_layers = src_parsed
19
~\Anaconda3\lib\site-packages\darkflow\dark\darknet.py in parse_cfg(self, model, FLAGS)
66 cfg_layers = cfg_yielder(*args)
67 meta = dict(); layers = list()
---> 68 for i, info in enumerate(cfg_layers):
69 if i == 0: meta = info; continue
70 else: new = create_darkop(*info)
~\Anaconda3\lib\site-packages\darkflow\utils\process.py in cfg_yielder(model, binary)
314 #-----------------------------------------------------
315 else:
--> 316 exit('Layer {} not
implemented'.format(d['type']))
317
318 d['_size'] = list([h, w, c, l, flat])
NameError: name 'exit' is not defined
So I faced the same problem and the issue is with the process.py file in
darkflow --> utils folder.
Apparently the exit() method is not in-built so you have to add this line in process.py
from sys import exit
Note : If your code is reaching this point it means the models can't read the layers. The weights file that I downloaded for yolov3 gave me same trouble and I couldn't find a link that has a proper weight file for yolov3 that works in darkflow. So I had to stick to yolo.cfg and yolo.weights .