matterport / Mask_RCNN

Mask R-CNN for object detection and instance segmentation on Keras and TensorFlow
Other
24.66k stars 11.7k forks source link

TypeError: integer argument expected, got float? #63

Closed kecaiwu closed 6 years ago

kecaiwu commented 6 years ago

I read the image from the images folder, and everything is ok. However, when read the '12283150_12d37e6389_z.jpg', I get the error, can you provide some advice?

Processing 1 images image shape: (375, 500, 3) min: 0.00000 max: 255.00000

TypeError Traceback (most recent call last)

in () 5 # Run detection 6 tic() ----> 7 results = model.detect([image], verbose=1) 8 toc() 9 print results[0]['masks'][0] /home/kecai/tf/Mask_RCNN/model.pyc in detect(self, images, verbose) 2205 log("image", image) 2206 # Mold inputs to format expected by the neural network -> 2207 molded_images, image_metas, windows = self.mold_inputs(images) 2208 if verbose: 2209 log("molded_images", molded_images) /home/kecai/tf/Mask_RCNN/model.pyc in mold_inputs(self, images) 2111 min_dim=self.config.IMAGE_MIN_DIM, 2112 max_dim=self.config.IMAGE_MAX_DIM, -> 2113 padding=self.config.IMAGE_PADDING) 2114 molded_image = mold_image(molded_image, self.config) 2115 # Build image_meta /home/kecai/tf/Mask_RCNN/utils.py in resize_image(image, min_dim, max_dim, padding) 393 if scale != 1: 394 image = scipy.misc.imresize( --> 395 image, (round(h * scale), round(w * scale))) 396 # Need padding? 397 if padding: /home/kecai/miniconda2/envs/kecai/lib/python2.7/site-packages/numpy/lib/utils.pyc in newfunc(*args, **kwds) 99 """`arrayrange` is deprecated, use `arange` instead!""" 100 warnings.warn(depdoc, DeprecationWarning, stacklevel=2) --> 101 return func(*args, **kwds) 102 103 newfunc = _set_function_name(newfunc, old_name) /home/kecai/miniconda2/envs/kecai/lib/python2.7/site-packages/scipy/misc/pilutil.pyc in imresize(arr, size, interp, mode) 562 size = (size[1], size[0]) 563 func = {'nearest': 0, 'lanczos': 1, 'bilinear': 2, 'bicubic': 3, 'cubic': 3} --> 564 imnew = im.resize(size, resample=func[interp]) 565 return fromimage(imnew) 566 /home/kecai/miniconda2/envs/kecai/lib/python2.7/site-packages/PIL/Image.pyc in resize(self, size, resample, box) 1743 self.load() 1744 -> 1745 return self._new(self.im.resize(size, resample, box)) 1746 1747 def rotate(self, angle, resample=NEAREST, expand=0, center=None, TypeError: integer argument expected, got float
crh19970307 commented 6 years ago

I have this problem when running demo for my own image. The error message is the same as yours. I change the IMAGE_MIN_DIM IMAGE_MAX_DIM in config.py to make your image size between the two variables. Maybe you can have a try.

Wauplin commented 6 years ago

Better solution is definitely to use Python3.4+ (see requirements) :wink:

Got the same issue using Python2.7 instead of Python3. It's due to the behavior of the round() function. In Python2.7 it's returning a floating number. You need to change line 394 in utils.py by " image, (int(round(h scale)), int(round(w scale)))) "

You should also have an issue when dividing 2 integers line385 and 390. You need to force Python2.7 to cast your integers to float before dividing (ex. scale = max(1, float(min_dim) / float(min(h, w))). Since this kind of issue is most of the time silent, I don't know how to chase them in the code.

waleedka commented 6 years ago

Thanks @Caunil . Closing the issue.

simaoh commented 6 years ago

@kecaiwu, To have the code run on Python2.7: 1) In utils.py, change resize_image as indicated by @Caunil; 2) In model.py, change lines: https://github.com/matterport/Mask_RCNN/blob/cbc21f65c25ffd8e5fea753f58d74d2faede7d64/model.py#L2281-L2282 to

        h_scale = float(image_shape[0]) / (window[2] - window[0])
        w_scale = float(image_shape[1]) / (window[3] - window[1]) 
BHAUMIKSINH7471 commented 5 years ago

w.addch(tail[0], tail[0], '')

TypeError: integer argument expected, got float

What To Do????

ABRAR-HAIDER commented 5 years ago

create_database.py import cv2, sys, numpy, os, time

count = 0 size = 4 fn_haar = 'haarcascade_frontalface_default.xml' fn_dir = 'database' fn_name = sys.argv[0]

name of the person

path = os.path.join(fn_dir, fn_name) if not os.path.isdir('C:/Users/Abrar Haider Rajput/Documents/faces/user'): os.mkdir(path) (im_width, im_height) = (112, 92) haar_cascade = cv2.CascadeClassifier(fn_haar) webcam = cv2.VideoCapture(0)

print "-----------------------Taking pictures----------------------" print "--------------------Give some expressions---------------------"

The program loops until it has 20 images of the face.

while count < 45: (rval, im) = webcam.read() im = cv2.flip(im, 1, 0) gray: None = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY) mini = (cv2.resize(gray, (gray.shape[1] / size, gray.shape[0] / size))) faces = haar_cascade.detectMultiScale(mini) faces = sorted(faces, key=lambda x: x[3]) if faces: face_i = faces[0] (x, y, w, h) = [v * size for v in face_i] face = gray[y:y + h, x:x + w] face_resize = cv2.resize(face, (im_width, im_height)) pin = sorted([int(n[:n.find('.')]) for n in os.listdir(path) if n[0] != '.'] + [0])[-1] + 1 cv2.imwrite('%s/%s.png' % (path, pin), face_resize) cv2.rectangle(im, (x, y), (x + w, y + h), (0, 255, 0), 3) cv2.putText(im, fn_name, (x - 10, y - 10), cv2.FONT_HERSHEY_PLAIN, 1, (0, 255, 0)) time.sleep(0.38) count += 1

cv2.imshow('OpenCV', im)
key = cv2.waitKey(10)
if key == 27:
    break

print str(count) + " images taken and saved to " + fn_name + " folder in database "

Traceback (most recent call last): File "C:/Users/Abrar Haider Rajput/.PyCharmCE2019.2/config/scratches/scratch.py", line 27, in mini = (cv2.resize(gray, (gray.shape[1] / 4, gray.shape[0] / 4))) TypeError: integer argument expected, got float [ WARN:0] global C:\projects\opencv-python\opencv\modules\videoio\src\cap_msmf.cpp (674) SourceReaderCB::~SourceReaderCB terminating async callback