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, 2020 in Python by Ganesh
• 120 points
524 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, 2020 by Gitika
• 65,870 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, 2020 by MD
• 95,140 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, 2020 in Python by MD
• 95,140 points
3,937 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
5,612 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
723 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
2,651 views
0 votes
2 answers
+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,989 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, 2020 in Python by MD
• 95,140 points
7,939 views
0 votes
3 answers

AttributeError: 'numpy.ndarray' object has no attribute 'append'

for root, dirs, files in os.walk(directory): ...READ MORE

answered Dec 11, 2020 in Python by Rajiv
• 8,880 points
31,439 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, 2020 in Python by Gitika
• 65,870 points
2,878 views