matterport / Mask_RCNN

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

model.detect() -> ValueError: too many values to unpack #469

Closed drewleonard closed 6 years ago

drewleonard commented 6 years ago

I'm working with demo.ipynb and am having trouble running model.detect(). Specifically, when running the following block of code:

image = skimage.io.imread(os.path.join(IMAGE_DIR, random.choice(file_names)))

# Run detection
results = model.detect([image], verbose=1)

# Visualize results
r = results[0]
visualize.display_instances(image, r['rois'], r['masks'], r['class_ids'], 
                            class_names, r['scores'])

the following error is returned:

ValueError                                Traceback (most recent call last)
<ipython-input-7-e987dabef485> in <module>()
      3 
      4 # Run detection
----> 5 results = model.detect([image], verbose=1)
      6 
      7 # Visualize results

/Users/drewnleonard/Documents/xview/mrcnn/model.pyc in detect(self, images, verbose)
   2442 
   2443         # Mold inputs to format expected by the neural network
-> 2444         molded_images, image_metas, windows = self.mold_inputs(images)
   2445 
   2446         # Validate image sizes

/Users/drewnleonard/Documents/xview/mrcnn/model.pyc in mold_inputs(self, images)
   2340                 min_dim=self.config.IMAGE_MIN_DIM,
   2341                 max_dim=self.config.IMAGE_MAX_DIM,
-> 2342                 mode=self.config.IMAGE_RESIZE_MODE)
   2343             molded_image = mold_image(molded_image, self.config)
   2344             # Build image_meta

ValueError: too many values to unpack

Any help on this issue would be much appreciated. Please let me know if I can provide extra information. Thank you very much!

drewleonard commented 6 years ago

This error was simple to fix: mold_inputs() in model.py calls the resize_image method from utils.py, but provides only 4 variables to receive the 5 values returned by resize_image (see below).

molded_image, window, scale, padding = utils.resize_image(
                image,
                min_dim=self.config.IMAGE_MIN_DIM,
                max_dim=self.config.IMAGE_MAX_DIM,
                min_scale=self.config.IMAGE_MIN_SCALE,
                mode=self.config.IMAGE_RESIZE_MODE
                )

To fix the ValueError this returns, supply an extra variable when calling resize_image:

molded_image, window, scale, padding, crop = utils.resize_image(
                image,
                min_dim=self.config.IMAGE_MIN_DIM,
                max_dim=self.config.IMAGE_MAX_DIM,
                min_scale=self.config.IMAGE_MIN_SCALE,
                mode=self.config.IMAGE_RESIZE_MODE
                )