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

Demo: InvalidArgumentError, GPU_COUNT=3 #299

Open isVoid opened 6 years ago

isVoid commented 6 years ago

Error: In Demo notebook, when using GPU_COUNT=3 and

# Load a random image from the images folder
file_names = next(os.walk(IMAGE_DIR))[2]
image1 = skimage.io.imread(os.path.join(IMAGE_DIR, random.choice(file_names)))
image2 = skimage.io.imread(os.path.join(IMAGE_DIR, random.choice(file_names)))
image3 = skimage.io.imread(os.path.join(IMAGE_DIR, random.choice(file_names)))

# Run detection
results = model.detect([image1, image2, image3], verbose=1)

# Visualize results
r = results[0]
visualize.display_instances(image1, r['rois'], r['masks'], r['class_ids'], 
                            class_names, r['scores'])
r = results[1]
visualize.display_instances(image2, r['rois'], r['masks'], r['class_ids'], 
                            class_names, r['scores'])
r = results[2]
visualize.display_instances(image3, r['rois'], r['masks'], r['class_ids'], 
                            class_names, r['scores'])

it shows

InvalidArgumentError: Input to reshape is a tensor with 600 values, but the requested shape has 1800

Environment: python3 tensorflow 1.4.0 Hardware: 3x Titan X

Full stack trace:

---------------------------------------------------------------------------
InvalidArgumentError                      Traceback (most recent call last)
~/tensorflow/envs/lib/python3.5/site-packages/tensorflow/python/client/session.py in _do_call(self, fn, *args)
   1322     try:
-> 1323       return fn(*args)
   1324     except errors.OpError as e:

~/tensorflow/envs/lib/python3.5/site-packages/tensorflow/python/client/session.py in _run_fn(session, feed_dict, fetch_list, target_list, options, run_metadata)
   1301                                    feed_dict, fetch_list, target_list,
-> 1302                                    status, run_metadata)
   1303 

~/tensorflow/envs/lib/python3.5/site-packages/tensorflow/python/framework/errors_impl.py in __exit__(self, type_arg, value_arg, traceback_arg)
    472             compat.as_text(c_api.TF_Message(self.status.status)),
--> 473             c_api.TF_GetCode(self.status.status))
    474     # Delete the underlying status object from memory otherwise it stays alive

InvalidArgumentError: Input to reshape is a tensor with 600 values, but the requested shape has 1800
     [[Node: tower_2/mask_rcnn/mrcnn_detection/Reshape_1 = Reshape[T=DT_FLOAT, Tshape=DT_INT32, _device="/job:localhost/replica:0/task:0/device:GPU:2"](tower_2/mask_rcnn/mrcnn_detection/packed, tower_2/mask_rcnn/mrcnn_detection/Reshape_1/shape)]]

During handling of the above exception, another exception occurred:

InvalidArgumentError                      Traceback (most recent call last)
<ipython-input-10-88f2c2a442e1> in <module>()
      6 
      7 # Run detection
----> 8 results = model.detect([image1, image2, image3], verbose=1)
      9 
     10 # Visualize results

/media/michael/Workspace/Mask_RCNN/model.py in detect(self, images, verbose)
   2366         detections, mrcnn_class, mrcnn_bbox, mrcnn_mask, \
   2367             rois, rpn_class, rpn_bbox =\
-> 2368             self.keras_model.predict([molded_images, image_metas], verbose=0)
   2369         # Process detections
   2370         results = []

~/tensorflow/envs/lib/python3.5/site-packages/keras/engine/training.py in predict(self, x, batch_size, verbose, steps)
   1840         f = self.predict_function
   1841         return self._predict_loop(f, ins, batch_size=batch_size,
-> 1842                                   verbose=verbose, steps=steps)
   1843 
   1844     def train_on_batch(self, x, y,

~/tensorflow/envs/lib/python3.5/site-packages/keras/engine/training.py in _predict_loop(self, f, ins, batch_size, verbose, steps)
   1335                     ins_batch[i] = ins_batch[i].toarray()
   1336 
-> 1337                 batch_outs = f(ins_batch)
   1338                 if not isinstance(batch_outs, list):
   1339                     batch_outs = [batch_outs]

~/tensorflow/envs/lib/python3.5/site-packages/keras/backend/tensorflow_backend.py in __call__(self, inputs)
   2473         session = get_session()
   2474         updated = session.run(fetches=fetches, feed_dict=feed_dict,
-> 2475                               **self.session_kwargs)
   2476         return updated[:len(self.outputs)]
   2477 

~/tensorflow/envs/lib/python3.5/site-packages/tensorflow/python/client/session.py in run(self, fetches, feed_dict, options, run_metadata)
    887     try:
    888       result = self._run(None, fetches, feed_dict, options_ptr,
--> 889                          run_metadata_ptr)
    890       if run_metadata:
    891         proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)

~/tensorflow/envs/lib/python3.5/site-packages/tensorflow/python/client/session.py in _run(self, handle, fetches, feed_dict, options, run_metadata)
   1118     if final_fetches or final_targets or (handle and feed_dict_tensor):
   1119       results = self._do_run(handle, final_targets, final_fetches,
-> 1120                              feed_dict_tensor, options, run_metadata)
   1121     else:
   1122       results = []

~/tensorflow/envs/lib/python3.5/site-packages/tensorflow/python/client/session.py in _do_run(self, handle, target_list, fetch_list, feed_dict, options, run_metadata)
   1315     if handle is None:
   1316       return self._do_call(_run_fn, self._session, feeds, fetches, targets,
-> 1317                            options, run_metadata)
   1318     else:
   1319       return self._do_call(_prun_fn, self._session, handle, feeds, fetches)

~/tensorflow/envs/lib/python3.5/site-packages/tensorflow/python/client/session.py in _do_call(self, fn, *args)
   1334         except KeyError:
   1335           pass
-> 1336       raise type(e)(node_def, op, message)
   1337 
   1338   def _extend_graph(self):

InvalidArgumentError: Input to reshape is a tensor with 600 values, but the requested shape has 1800
     [[Node: tower_2/mask_rcnn/mrcnn_detection/Reshape_1 = Reshape[T=DT_FLOAT, Tshape=DT_INT32, _device="/job:localhost/replica:0/task:0/device:GPU:2"](tower_2/mask_rcnn/mrcnn_detection/packed, tower_2/mask_rcnn/mrcnn_detection/Reshape_1/shape)]]

Caused by op 'tower_2/mask_rcnn/mrcnn_detection/Reshape_1', defined at:
  File "/usr/lib/python3.5/runpy.py", line 184, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/michael/tensorflow/envs/lib/python3.5/site-packages/ipykernel_launcher.py", line 16, in <module>
    app.launch_new_instance()
  File "/home/michael/tensorflow/envs/lib/python3.5/site-packages/traitlets/config/application.py", line 658, in launch_instance
    app.start()
  File "/home/michael/tensorflow/envs/lib/python3.5/site-packages/ipykernel/kernelapp.py", line 477, in start
    ioloop.IOLoop.instance().start()
  File "/home/michael/tensorflow/envs/lib/python3.5/site-packages/zmq/eventloop/ioloop.py", line 177, in start
    super(ZMQIOLoop, self).start()
  File "/home/michael/tensorflow/envs/lib/python3.5/site-packages/tornado/ioloop.py", line 888, in start
    handler_func(fd_obj, events)
  File "/home/michael/tensorflow/envs/lib/python3.5/site-packages/tornado/stack_context.py", line 277, in null_wrapper
    return fn(*args, **kwargs)
  File "/home/michael/tensorflow/envs/lib/python3.5/site-packages/zmq/eventloop/zmqstream.py", line 440, in _handle_events
    self._handle_recv()
  File "/home/michael/tensorflow/envs/lib/python3.5/site-packages/zmq/eventloop/zmqstream.py", line 472, in _handle_recv
    self._run_callback(callback, msg)
  File "/home/michael/tensorflow/envs/lib/python3.5/site-packages/zmq/eventloop/zmqstream.py", line 414, in _run_callback
    callback(*args, **kwargs)
  File "/home/michael/tensorflow/envs/lib/python3.5/site-packages/tornado/stack_context.py", line 277, in null_wrapper
    return fn(*args, **kwargs)
  File "/home/michael/tensorflow/envs/lib/python3.5/site-packages/ipykernel/kernelbase.py", line 283, in dispatcher
    return self.dispatch_shell(stream, msg)
  File "/home/michael/tensorflow/envs/lib/python3.5/site-packages/ipykernel/kernelbase.py", line 235, in dispatch_shell
    handler(stream, idents, msg)
  File "/home/michael/tensorflow/envs/lib/python3.5/site-packages/ipykernel/kernelbase.py", line 399, in execute_request
    user_expressions, allow_stdin)
  File "/home/michael/tensorflow/envs/lib/python3.5/site-packages/ipykernel/ipkernel.py", line 196, in do_execute
    res = shell.run_cell(code, store_history=store_history, silent=silent)
  File "/home/michael/tensorflow/envs/lib/python3.5/site-packages/ipykernel/zmqshell.py", line 533, in run_cell
    return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)
  File "/home/michael/tensorflow/envs/lib/python3.5/site-packages/IPython/core/interactiveshell.py", line 2728, in run_cell
    interactivity=interactivity, compiler=compiler, result=result)
  File "/home/michael/tensorflow/envs/lib/python3.5/site-packages/IPython/core/interactiveshell.py", line 2850, in run_ast_nodes
    if self.run_code(code, result):
  File "/home/michael/tensorflow/envs/lib/python3.5/site-packages/IPython/core/interactiveshell.py", line 2910, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-3-138183a2a830>", line 2, in <module>
    model = modellib.MaskRCNN(mode="inference", model_dir=MODEL_DIR, config=config)
  File "/media/michael/Workspace/Mask_RCNN/model.py", line 1763, in __init__
    self.keras_model = self.build(mode=mode, config=config)
  File "/media/michael/Workspace/Mask_RCNN/model.py", line 1974, in build
    model = ParallelModel(model, config.GPU_COUNT)
  File "/media/michael/Workspace/Mask_RCNN/parallel_model.py", line 37, in __init__
    merged_outputs = self.make_parallel()
  File "/media/michael/Workspace/Mask_RCNN/parallel_model.py", line 81, in make_parallel
    outputs = self.inner_model(inputs)
  File "/home/michael/tensorflow/envs/lib/python3.5/site-packages/keras/engine/topology.py", line 617, in __call__
    output = self.call(inputs, **kwargs)
  File "/home/michael/tensorflow/envs/lib/python3.5/site-packages/keras/engine/topology.py", line 2081, in call
    output_tensors, _, _ = self.run_internal_graph(inputs, masks)
  File "/home/michael/tensorflow/envs/lib/python3.5/site-packages/keras/engine/topology.py", line 2243, in run_internal_graph
    output_tensors = _to_list(layer.call(computed_tensors, **kwargs))
  File "/media/michael/Workspace/Mask_RCNN/model.py", line 804, in call
    [self.config.BATCH_SIZE, self.config.DETECTION_MAX_INSTANCES, 6])
  File "/home/michael/tensorflow/envs/lib/python3.5/site-packages/tensorflow/python/ops/gen_array_ops.py", line 3938, in reshape
    "Reshape", tensor=tensor, shape=shape, name=name)
  File "/home/michael/tensorflow/envs/lib/python3.5/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
    op_def=op_def)
  File "/home/michael/tensorflow/envs/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 2956, in create_op
    op_def=op_def)
  File "/home/michael/tensorflow/envs/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 1470, in __init__
    self._traceback = self._graph._extract_stack()  # pylint: disable=protected-access

InvalidArgumentError (see above for traceback): Input to reshape is a tensor with 600 values, but the requested shape has 1800
     [[Node: tower_2/mask_rcnn/mrcnn_detection/Reshape_1 = Reshape[T=DT_FLOAT, Tshape=DT_INT32, _device="/job:localhost/replica:0/task:0/device:GPU:2"](tower_2/mask_rcnn/mrcnn_detection/packed, tower_2/mask_rcnn/mrcnn_detection/Reshape_1/shape)]]
adamfaskowitz commented 6 years ago

did you ever find the solution to this problem? I am dealing with the same.

keineahnung2345 commented 6 years ago

Did you train the model with 1 GPU? I guess it's because one cannot do multiple GPU inference using a model that is trained on 1 GPU.

svpino commented 4 years ago

This is also happening to me.