module 'numpy' has no attribute 'unit8'

0 votes
Respected Sir/Madam

I am trying to run the below Image segmentation code in my system, but it is showing me an error.

import cv2
import numpy as np
import matplotlib.pyplot as plt
image=cv2.imread("nn.jpg")
image=cv2.cvtColor(image,cv2.COLOR_BGR2RGB)
pixel_values=image.reshape((-1,3))
pixel_values=np.float32(pixel_values)
print(pixel_values.shape)
criteria=(cv2.TERM_CRITERIA_EPS+cv2.TERM_CRITERIA_MAX_ITER,100,0.2)
k=3
_,labels,(centers)=cv2.kmeans(pixel_values,k,None,criteria,10,cv2.KMEANS_RANDOM_CENTERS)
centers=np.unit8(centers)
labels=labels.flatten()
segmented_image=centers[labels.flatten()]
segmented_image=segmented_image.reshape(image.shape)
plt.imshow(segmented_image)
plt.show()
module 'numpy' has no attribute 'unit8'
Sep 22 in Python by Ganesh
• 120 points
121 views

2 answers to this question.

0 votes

Hi, @Ganesh,

You have used unit8 in your code. But NumPy has no attribute named unit8. You have to use uint8 instead of unit8 in your code. So make changes in your code and try once again. It will work.

answered Sep 22 by Gitika
• 41,360 points
0 votes

Hi@Ganesh,

I think you are calling the wrong function from your Numpy module. The Numpy module doesn't have unit8(). Just replace unit8() with uint8(). It will work.

answered Sep 22 by MD
• 65,200 points

Related Questions In Python

0 votes
1 answer

module 'numpy' has no attribute 'unit8'

Hi@akhtar, You have used unit8 in your code. ...READ MORE

answered Jun 22 in Python by MD
• 65,200 points
1,449 views
0 votes
1 answer

Getting AttributeError: 'module' object (scipy) has no attribute 'misc' in Python. How to solve this?

>>> import scipy >>> scipy.misc Traceback (most recent call ...READ MORE

answered Dec 24, 2018 in Python by Nymeria
• 3,520 points
4,274 views
0 votes
0 answers

'module' object has no attribute 'PortScanner'

I am trying to run nmap in ...READ MORE

Jan 30, 2019 in Python by Karan
607 views
0 votes
1 answer

Python error "AttributeError: '_Screen' object has no attribute 'mainloop'" python module turtle

Hey @Nagya, replace  wn.mainlopp() with turtle.mainloop() ...READ MORE

answered Jun 19, 2019 in Python by Faiza
1,695 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,452 views
0 votes
0 answers
0 votes
1 answer

AttributeError: module 'numpy' has no attribute '__version__'

Hi@akhtar, To avoid this error you can use ...READ MORE

answered Apr 20 in Python by MD
• 65,200 points
3,558 views
0 votes
1 answer

AttributeError: type object 'DataFrame' has no attribute 'from_items'

Hi, @Bronson, You can go through this, I ...READ MORE

answered Apr 6 in Python by Gitika
• 41,360 points
1,551 views
0 votes
1 answer