broadinstitute / keras-rcnn

Keras package for region-based convolutional neural networks (RCNNs)
Other
553 stars 224 forks source link

invalid syntax in keras_rcnn\models\_rpn.py line 169 #157

Open ChiaoSun opened 6 years ago

ChiaoSun commented 6 years ago

Hi, I got a SyntaxError: invalid syntax in

keras_rcnn\models_rpn.py", line 169 name = f"p{index + 2}"

I use anaconda 3 and python 3.5, anyone can help me fix this problem?

chituma110 commented 6 years ago

I have meet the same problem. Have you solved the problem?@ChiaoSun

ChiaoSun commented 6 years ago

Hi @chituma110 , I haven't 100% solved this problem yet. But I already know this problem caused by the new string format in python 3.6. Therefore, I replace line 169 with name = "p{0}".format(str(index+2)) which suit on python 3.5. It looks like solved this error but get another error. Maybe you can try it.

patruff commented 6 years ago

I too get this error, using Windows 8, python 3.5

jhung0 commented 6 years ago

We're using python 3.6 ...sorry, never tried on 3.5

wolfman30 commented 6 years ago

**After running this line from akshaybapat04: <name = "p{index_substi + 2}".format(index_substri = index)> I get the following error:**

InvalidArgumentError Traceback (most recent call last) /usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/common_shapes.py in _call_cpp_shape_fn_impl(op, input_tensors_needed, input_tensors_as_shapes_needed, require_shape_fn) 653 graph_def_version, node_def_str, input_shapes, input_tensors, --> 654 input_tensors_as_shapes, status) 655 except errors.InvalidArgumentError as err:

/usr/lib/python3.5/contextlib.py in exit(self, type, value, traceback) 65 try: ---> 66 next(self.gen) 67 except StopIteration:

/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/errors_impl.py in raise_exception_on_not_ok_status() 465 compat.as_text(pywrap_tensorflow.TF_Message(status)), --> 466 pywrap_tensorflow.TF_GetCode(status)) 467 finally:

InvalidArgumentError: indices.shape[-1] must be <= params.rank, but saw indices shape: [1,?,3] and params shape: [1,?] for 'rpn_8/GatherNd_1' (op: 'GatherNd') with input shapes: [1,?], [1,?,3].

During handling of the above exception, another exception occurred:

ValueError Traceback (most recent call last)

in () 3 image = keras.layers.Input((None, None, 3)) 4 ----> 5 model = RCNN(image, classes=len(classes) + 1) ~/keras-rcnn/keras_rcnn/models/_rcnn.py in __init__(self, target_image, classes) 64 target_anchors, target_proposal_labels, target_proposals = keras_rcnn.layers.AnchorTarget()([output_scores, target_bounding_boxes, target_metadata]) 65 ---> 66 output_deltas, output_scores = keras_rcnn.layers.RPN()([output_deltas, target_proposals, output_scores, target_proposal_labels]) 67 68 output_proposals = keras_rcnn.layers.ObjectProposal()([target_metadata, output_deltas, output_scores, target_anchors]) /usr/local/lib/python3.5/dist-packages/keras/engine/topology.py in __call__(self, inputs, **kwargs) 615 616 # Actually call the layer, collecting output(s), mask(s), and shape(s). --> 617 output = self.call(inputs, **kwargs) 618 output_mask = self.compute_mask(inputs, previous_mask) 619 ~/keras-rcnn/keras_rcnn/layers/losses/__init__.py in call(self, inputs, **kwargs) 74 self.output_scores = keras.backend.reshape(output_scores, (1, -1)) 75 ---> 76 self.add_loss(self.classification_loss() + self.regression_loss()) 77 78 return [output_deltas, output_scores] ~/keras-rcnn/keras_rcnn/layers/losses/__init__.py in classification_loss(self) 86 87 target = keras_rcnn.backend.gather_nd(self.target_scores, indices) ---> 88 output = keras_rcnn.backend.gather_nd(self.output_scores, indices) 89 90 loss = keras.backend.binary_crossentropy(target, output) ~/keras-rcnn/keras_rcnn/backend/tensorflow_backend.py in gather_nd(params, indices) 53 54 def gather_nd(params, indices): ---> 55 return tensorflow.gather_nd(params, indices) 56 57 /usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/gen_array_ops.py in gather_nd(params, indices, name) 1336 """ 1337 result = _op_def_lib.apply_op("GatherNd", params=params, indices=indices, -> 1338 name=name) 1339 return result 1340 /usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/op_def_library.py in apply_op(self, op_type_name, name, **keywords) 765 op = g.create_op(op_type_name, inputs, output_types, name=scope, 766 input_types=input_types, attrs=attr_protos, --> 767 op_def=op_def) 768 if output_structure: 769 outputs = op.outputs /usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py in create_op(self, op_type, inputs, dtypes, input_types, name, attrs, op_def, compute_shapes, compute_device) 2630 original_op=self._default_original_op, op_def=op_def) 2631 if compute_shapes: -> 2632 set_shapes_for_outputs(ret) 2633 self._add_op(ret) 2634 self._record_op_seen_by_control_dependencies(ret) /usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py in set_shapes_for_outputs(op) 1909 shape_func = _call_cpp_shape_fn_and_require_op 1910 -> 1911 shapes = shape_func(op) 1912 if shapes is None: 1913 raise RuntimeError( /usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py in call_with_requiring(op) 1859 1860 def call_with_requiring(op): -> 1861 return call_cpp_shape_fn(op, require_shape_fn=True) 1862 1863 _call_cpp_shape_fn_and_require_op = call_with_requiring /usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/common_shapes.py in call_cpp_shape_fn(op, require_shape_fn) 593 res = _call_cpp_shape_fn_impl(op, input_tensors_needed, 594 input_tensors_as_shapes_needed, --> 595 require_shape_fn) 596 if not isinstance(res, dict): 597 # Handles the case where _call_cpp_shape_fn_impl calls unknown_shape(op). /usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/common_shapes.py in _call_cpp_shape_fn_impl(op, input_tensors_needed, input_tensors_as_shapes_needed, require_shape_fn) 657 missing_shape_fn = True 658 else: --> 659 raise ValueError(err.message) 660 661 if missing_shape_fn: **ValueError:** indices.shape[-1] must be <= params.rank, but saw indices shape: [1,?,3] and params shape: [1,?] for 'rpn_8/GatherNd_1' (op: 'GatherNd') with input shapes: [1,?], [1,?,3]. **Even after changing the fixed line to these two alternatives:** name = "p{index_subst**r**i + 2}".format(index_subst**r**i = index) name = "p{index_sub**sti** + 2}".format(index_sub**sti** = index) **I get the same kind of error, the InvalidArgumentError and ValueError**