keras-rcnn
keras-rcnn copied to clipboard
InvalidArgumentError when running `keras_rcnn.models.RPN`
The following code:
model = keras_rcnn.models.RPN(image, classes)
model.compile("adam")
prediction = model.predict_generator(generator)
throws the following InvalidArgumentError
exception:
InvalidArgumentError: You must feed a value for placeholder tensor 'proposal_target_1/keras_learning_phase' with dtype bool
[[Node: proposal_target_1/keras_learning_phase = Placeholder[dtype=DT_BOOL, shape=<unknown>, _device="/job:localhost/replica:0/task:0/device:GPU:0"]()]]
[[Node: proposal_target_1/cond/Reshape_1/_465 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device_incarnation=1, tensor_name="edge_794_proposal_target_1/cond/Reshape_1", tensor_type=DT_INT64, _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]
Caused by op 'proposal_target_1/keras_learning_phase', defined at:
File "/usr/local/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/local/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/usr/local/lib/python3.6/site-packages/ipykernel_launcher.py", line 16, in <module>
app.launch_new_instance()
File "/usr/local/lib/python3.6/site-packages/traitlets/config/application.py", line 658, in launch_instance
app.start()
File "/usr/local/lib/python3.6/site-packages/ipykernel/kernelapp.py", line 478, in start
self.io_loop.start()
File "/usr/local/lib/python3.6/site-packages/zmq/eventloop/ioloop.py", line 177, in start
super(ZMQIOLoop, self).start()
File "/usr/local/lib/python3.6/site-packages/tornado/ioloop.py", line 888, in start
handler_func(fd_obj, events)
File "/usr/local/lib/python3.6/site-packages/tornado/stack_context.py", line 277, in null_wrapper
return fn(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/zmq/eventloop/zmqstream.py", line 440, in _handle_events
self._handle_recv()
File "/usr/local/lib/python3.6/site-packages/zmq/eventloop/zmqstream.py", line 472, in _handle_recv
self._run_callback(callback, msg)
File "/usr/local/lib/python3.6/site-packages/zmq/eventloop/zmqstream.py", line 414, in _run_callback
callback(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/tornado/stack_context.py", line 277, in null_wrapper
return fn(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/ipykernel/kernelbase.py", line 281, in dispatcher
return self.dispatch_shell(stream, msg)
File "/usr/local/lib/python3.6/site-packages/ipykernel/kernelbase.py", line 232, in dispatch_shell
handler(stream, idents, msg)
File "/usr/local/lib/python3.6/site-packages/ipykernel/kernelbase.py", line 397, in execute_request
user_expressions, allow_stdin)
File "/usr/local/lib/python3.6/site-packages/ipykernel/ipkernel.py", line 208, in do_execute
res = shell.run_cell(code, store_history=store_history, silent=silent)
File "/usr/local/lib/python3.6/site-packages/ipykernel/zmqshell.py", line 533, in run_cell
return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2728, in run_cell
interactivity=interactivity, compiler=compiler, result=result)
File "/usr/local/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2850, in run_ast_nodes
if self.run_code(code, result):
File "/usr/local/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2910, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-5-0718d9c36cf7>", line 1, in <module>
model = keras_rcnn.models.RPN(image, classes=len(classes) + 1)
File "/home/0x00b1/com/github/broadinstitute/keras-rcnn/keras_rcnn/models/_rpn.py", line 165, in __init__
proposals, labels_targets, bounding_box_targets = keras_rcnn.layers.ProposalTarget()([proposals, labels, bounding_boxes])
File "/usr/local/lib/python3.6/site-packages/keras/engine/topology.py", line 603, in __call__
output = self.call(inputs, **kwargs)
File "/home/0x00b1/com/github/broadinstitute/keras-rcnn/keras_rcnn/layers/object_detection/_proposal_target.py", line 70, in call
sample_outputs = self.sample_rois(proposals, bounding_boxes, labels, training)
File "/home/0x00b1/com/github/broadinstitute/keras-rcnn/keras_rcnn/layers/object_detection/_proposal_target.py", line 126, in sample_rois
rois = keras.backend.in_train_phase(rois, all_rois, training=training)
File "/usr/local/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 2740, in in_train_phase
training = learning_phase()
File "/usr/local/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 121, in learning_phase
name='keras_learning_phase')
File "/usr/local/lib/python3.6/site-packages/tensorflow/python/ops/array_ops.py", line 1680, in placeholder
return gen_array_ops._placeholder(dtype=dtype, shape=shape, name=name)
File "/usr/local/lib/python3.6/site-packages/tensorflow/python/ops/gen_array_ops.py", line 3141, in _placeholder
"Placeholder", dtype=dtype, shape=shape, name=name)
File "/usr/local/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
op_def=op_def)
File "/usr/local/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3160, in create_op
op_def=op_def)
File "/usr/local/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1625, in __init__
self._traceback = self._graph._extract_stack() # pylint: disable=protected-access
InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'proposal_target_1/keras_learning_phase' with dtype bool
[[Node: proposal_target_1/keras_learning_phase = Placeholder[dtype=DT_BOOL, shape=<unknown>, _device="/job:localhost/replica:0/task:0/device:GPU:0"]()]]
[[Node: proposal_target_1/cond/Reshape_1/_465 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device_incarnation=1, tensor_name="edge_794_proposal_target_1/cond/Reshape_1", tensor_type=DT_INT64, _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]
It works if I explicitly disable the learning phase:
keras.backend.set_learning_phase(False)
model = keras_rcnn.models.RPN(image, classes=len(classes) + 1)
model.compile("adam")
x, _ = generator.next()
prediction = model.predict(x)
I suppose this confirms that this an issue with the in_train_phase
logic inside ProposalTarget
.