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
2,829 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,890 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,460 points

Related Questions In Python

+1 vote
1 answer

module 'numpy' has no attribute 'unit8'

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

answered Jun 23, 2020 in Python by MD
• 95,460 points
15,603 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,560 points
9,311 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
1,375 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
7,137 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 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,364 views
0 votes
1 answer
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,460 points
21,026 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 12, 2020 in Python by Rajiv
• 8,910 points
52,772 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,890 points
5,247 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP