fizyr / keras-retinanet

Keras implementation of RetinaNet object detection.
Apache License 2.0
4.38k stars 1.96k forks source link

Change made on Anchor parameters is not working. #1391

Closed kmanojkkmr closed 4 years ago

kmanojkkmr commented 4 years ago

When I changed ratios to 5 values in Anchor parameters using config.ini file I am getting the below error while testing.


InvalidArgumentError Traceback (most recent call last)

in ----> 1 show_detected_objects(test_df.iloc[1]) in show_detected_objects(image_row, images_save_dir) 6 image = read_image_bgr(img_path) 7 ----> 8 boxes, scores, labels = predict(image) 9 10 draw = image.copy() in predict(image) 5 6 ----> 7 boxes, scores, labels = model.predict_on_batch(np.expand_dims(image, axis=0)) 8 # boxes, scores, labels = pickle_model.predict(np.expand_dims(image, axis=0)) 9 ~\.conda\envs\table_detection\lib\site-packages\keras\engine\training.py in predict_on_batch(self, x) 1578 ins = x 1579 self._make_predict_function() -> 1580 outputs = self.predict_function(ins) 1581 return unpack_singleton(outputs) 1582 ~\.conda\envs\table_detection\lib\site-packages\tensorflow\python\keras\backend.py in __call__(self, inputs) 3790 value = math_ops.cast(value, tensor.dtype) 3791 converted_inputs.append(value) -> 3792 outputs = self._graph_fn(*converted_inputs) 3793 3794 # EagerTensor.numpy() will often make a copy to ensure memory safety. ~\.conda\envs\table_detection\lib\site-packages\tensorflow\python\eager\function.py in __call__(self, *args, **kwargs) 1603 TypeError: For invalid positional/keyword argument combinations. 1604 """ -> 1605 return self._call_impl(args, kwargs) 1606 1607 def _call_impl(self, args, kwargs, cancellation_manager=None): ~\.conda\envs\table_detection\lib\site-packages\tensorflow\python\eager\function.py in _call_impl(self, args, kwargs, cancellation_manager) 1643 raise TypeError("Keyword arguments {} unknown. Expected {}.".format( 1644 list(kwargs.keys()), list(self._arg_keywords))) -> 1645 return self._call_flat(args, self.captured_inputs, cancellation_manager) 1646 1647 def _filtered_call(self, args, kwargs): ~\.conda\envs\table_detection\lib\site-packages\tensorflow\python\eager\function.py in _call_flat(self, args, captured_inputs, cancellation_manager) 1744 # No tape is watching; skip to running the function. 1745 return self._build_call_outputs(self._inference_function.call( -> 1746 ctx, args, cancellation_manager=cancellation_manager)) 1747 forward_backward = self._select_forward_and_backward_functions( 1748 args, ~\.conda\envs\table_detection\lib\site-packages\tensorflow\python\eager\function.py in call(self, ctx, args, cancellation_manager) 596 inputs=args, 597 attrs=attrs, --> 598 ctx=ctx) 599 else: 600 outputs = execute.execute_with_cancellation( ~\.conda\envs\table_detection\lib\site-packages\tensorflow\python\eager\execute.py in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name) 58 ctx.ensure_initialized() 59 tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name, ---> 60 inputs, attrs, num_outputs) 61 except core._NotOkStatusException as e: 62 if name is not None: **InvalidArgumentError: Incompatible shapes: [1,433975] vs. [1,156231]** [[node boxes_29/mul_5 (defined at C:\Users\manoj.kadamalakaluva\.conda\envs\table_detection\lib\site-packages\keras\backend\tensorflow_backend.py:3009) ]] [Op:__inference_keras_scratch_graph_431233] Function call stack: keras_scratch_graph
Gateway2745 commented 4 years ago

Did you pass your new config.ini while converting your model from training to inference? See #1233

kmanojkkmr commented 4 years ago

Thanks for the headup. :) @Gateway2745 I have passed the config parameters to models.convert_model(models, anchor_params). Now i am able to get the expected result.

Changes I have made: Before Change: model = models.load_model(model_path, backbone_name='resnet50') model = models.convert_model(model)

After Changes:

model = models.load_model(model_path, backbone_name='resnet50') config_file = r'config.ini' anchor_parameters = None if config_file: config_file = read_config_file(config_file) if 'anchor_parameters' in config_file: anchor_parameters = parse_anchor_parameters(config_file)

model = models.convert_model(model, anchor_params=anchor_parameters)

Run the below code in the terminal python keras_retinanet/bin/train.py --weights ./snapshots/resnet50_csv_10.h5 --config config.ini --freeze-backbone --random-transform --batch-size 8 --steps 1 --epochs 1 csv train.csv classes.csv

Hope this helps to someone who wants to make changes for prediction.