I am new to object detetctio and trying to run code for simple object detection on google colab, please help me with the solution
import cv2
import numpy as np
import matplotlib.pyplot as plt
import cvlib as cv
from cvlib.object_detection import draw_bbox
from numpy.lib.polynomial import poly
img = cv2.imread("/content/banner.jpg")
img1 = cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
plt.figure(figsize=(10,10))
plt.axis("off")
plt.imshow(img1)
plt.show()
box, label,count = cv.detect_common_objects(img)
#output = draw_bbox(img, box,label, count)
but it is giving error as
error: OpenCV(3.4.3) /io/opencv/modules/dnn/src/darknet/darknet_io.cpp:552: error: (-212:Parsing error) Unsupported activation: mish in function 'ReadDarknetFromCfgStream'
Are you running object detection on Yolov4?
If yes, please note that Yolov4 is not supported by Opencv 4.2.0 and 4.3.0.
Try to download the last version in master branch support YoloV4 (according to KyloEntro)
Personally, I have upgraded opencv-python to version 4.5.3.56, and there is no more error!
please update your opencv, more recent versions have a proper mish activation
import cvlib as cv
DONT use 3rd party libs built on top of opencv, since you have no control about versioning, and noone knows about those enough to help you
Related
My environment: Anaconda, Python 3.8.8, Pytorch1.8.1+cu111
Question: When I run the code below I get the following error:
UserWarning: "D:\Anaconda3\envs\pytorch\lib\site-packages\torch\cuda\amp\autocast_mode.py:5: UserWarning: The NumPy module was reloaded (imported a second time). This can in some cases result in small but subtle issues and is discouraged."
Code:
from PIL import Image
from torchvision import transforms
img_path = "data/train/ants_image/0013035.jpg"
img = Image.open(img_path)
tensor_trains = transforms.ToTensor()
tensor_img = tensor_trains(img)
print(tensor_img)
But the code work. Why does the above error message appear?
I am struggling with an error called 'function' object has no attribute 'fft2'. First of all,
I have imported the following:
import cv2
import matplotlib.pyplot as plt
import numpy as np
from scipy import fft
After executing the following block of code in jupyter notebook:
gainDisplay=1
InImgFFT=fft.fft2(InImg,norm="ortho")
InImgAmplSpec=np.abs(fft.fftshift(InImgFFT))
plt.figure(figsize=(W/DPI+1,H/DPI+1))
plt.imshow(np.clip(InImgAmplSpec*gainDisplay,0,255),cmap = 'rainbow')
plt.suptitle('The amplitude spectrum of the gray scale input image')
plt.show()
I get the error mentioned at the line with fft.fft2() function
Could you please help me to solve this error?
scipy version is 1.5.2
Another mention would be that I have a conda environment where i have installed all the packets, but I hope that won't be a problem.
I want to use OpenCV's perceptual hashing functions from Python.
This isn't working.
import cv2
a_1 = cv2.imread('a.jpg')
cv2.img_hash_BlockMeanHash.compute(a_1)
I get:
TypeError: descriptor 'compute' requires a 'cv2.img_hash_ImgHashBase' object but received a 'numpy.ndarray'
And this is failing too
a_1_base = cv2.img_hash_ImgHashBase(a_1)
cv2.img_hash_BlockMeanHash.compute(a_1_base)
I get:
TypeError: Incorrect type of self (must be 'img_hash_ImgHashBase' or its derivative)
Colab notebook showing this:
https://colab.research.google.com/drive/1x5ZxMBD3wFts2WKS4ip3rp4afDx0lGhi
It's a common compatibility gap that the OpenCV python interface has with the C++ interface (i.e. the classes don't inherit from each other the same way). There are the *_create() static functions for that.
So you should use:
hsh = cv2.img_hash.BlockMeanHash_create()
hsh.compute(a_1)
In a copy of your collab notebook:
https://colab.research.google.com/drive/1CLJNPPbeO3CiQ2d8JgPxEINpr2oNMWPh#scrollTo=OdTtUegmPnf2
pip install opencv-python
pip install opencv-contrib-python #img_hash in this one
(https://pypi.org/project/opencv-python/)
Here I show you how to compute 64-bit pHash with OpenCV.
I defined a function which returns unsigned, 64-bit integer pHash from a color BGR cv2 image passed-in:
import cv2
def pHash(cv_image):
imgg = cv2.cvtColor(cv_image, cv2.COLOR_BGR2GRAY);
h=cv2.img_hash.pHash(imgg) # 8-byte hash
pH=int.from_bytes(h.tobytes(), byteorder='big', signed=False)
return pH
You need to have installed and import cv2 for this to work.
When attempting to pass my RNN call, I call tf.nn.rnn_cell and I receive the following error:
AttributeError: module 'tensorflow.python.ops.nn' has no attribute 'rnn_cell'
Which is odd, because I'm sure I imported everything correctly:
from __future__ import print_function, division
from tensorflow.contrib import rnn
import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt
But looking at the docs, things have moved around between tensorflow versions.
what would you all recommend to fix this??
Line, I'm getting the error against:
state_per_layer_list = tf.unstack(init_state, axis=0)
rnn_tuple_state = tuple(
[tf.nn.rnn_cell.LSTMStateTuple(state_per_layer_list[idx][0], state_per_layer_list[idx][1])
for idx in range(num_layers)]
)
Specifically:
tf.nn.rnn_cell
I'm using anaconda 3 to manage all of this so, the dependancies should all be taken care of. I have already tried working around a damn rank/shape error with Tensor shapes which took ages to resolve.
Cheers in advance.
Replace tf.nn.rnn_cell with tf.contrib.rnn
Since version 1.0, rnn implemented as part of the contrib module.
More information can be found here
https://www.tensorflow.org/api_guides/python/contrib.rnn
I am using opencv3.1.0.
While I am trying to run:
import cv2.cv as cv
import cv2
cascade = cv.Load('/usr/share/OpenCV/haarcascades/haarcascade_frontalface_alt2.xml')
I find that cv2.cv is not in opencv3, so I change cv2.cv to cv2
and then I get the error message in the title.
Any thoughts?
Many thanks.
You are trying to load a classifier from a file, correct?
According to the OpenCV3 documentation you should use CascadeClassifier for this.
Example:
import cv2
cascade = cv2.CascadeClassifier('/usr/share/OpenCV/haarcascades/haarcascade_frontalface_alt2.xml')
Source: http://docs.opencv.org/3.0-beta/modules/objdetect/doc/cascade_classification.html