xuannianz / EfficientDet

EfficientDet (Scalable and Efficient Object Detection) implementation in Keras and Tensorflow
Apache License 2.0
1.39k stars 395 forks source link

I got error in model.predict_on_batch #233

Closed Vova-B closed 3 years ago

Vova-B commented 3 years ago

I try to start inference.py and get error IndexError: list index out of range . What could be the problem?

Full error code:

Traceback (most recent call last):
  File "inference_video.py", line 68, in <module>
    main()
  File "inference_video.py", line 49, in main
    boxes, scores, labels = model.predict_on_batch([np.expand_dims(image, axis=0)])
  File "/home/vladimir/anaconda3/envs/effdet_tf/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py", line 1820, in predict_on_batch
    outputs = self.predict_function(iterator)
  File "/home/vladimir/anaconda3/envs/effdet_tf/lib/python3.7/site-packages/tensorflow/python/eager/def_function.py", line 828, in __call__
    result = self._call(*args, **kwds)
  File "/home/vladimir/anaconda3/envs/effdet_tf/lib/python3.7/site-packages/tensorflow/python/eager/def_function.py", line 871, in _call
    self._initialize(args, kwds, add_initializers_to=initializers)
  File "/home/vladimir/anaconda3/envs/effdet_tf/lib/python3.7/site-packages/tensorflow/python/eager/def_function.py", line 726, in _initialize
    *args, **kwds))
  File "/home/vladimir/anaconda3/envs/effdet_tf/lib/python3.7/site-packages/tensorflow/python/eager/function.py", line 2969, in _get_concrete_function_internal_garbage_collected
    graph_function, _ = self._maybe_define_function(args, kwargs)
  File "/home/vladimir/anaconda3/envs/effdet_tf/lib/python3.7/site-packages/tensorflow/python/eager/function.py", line 3361, in _maybe_define_function
    graph_function = self._create_graph_function(args, kwargs)
  File "/home/vladimir/anaconda3/envs/effdet_tf/lib/python3.7/site-packages/tensorflow/python/eager/function.py", line 3206, in _create_graph_function
    capture_by_value=self._capture_by_value),
  File "/home/vladimir/anaconda3/envs/effdet_tf/lib/python3.7/site-packages/tensorflow/python/framework/func_graph.py", line 990, in func_graph_from_py_func
    func_outputs = python_func(*func_args, **func_kwargs)
  File "/home/vladimir/anaconda3/envs/effdet_tf/lib/python3.7/site-packages/tensorflow/python/eager/def_function.py", line 634, in wrapped_fn
    out = weak_wrapped_fn().__wrapped__(*args, **kwds)
  File "/home/vladimir/anaconda3/envs/effdet_tf/lib/python3.7/site-packages/tensorflow/python/framework/func_graph.py", line 977, in wrapper
    raise e.ag_error_metadata.to_exception(e)
tensorflow.python.autograph.impl.api.StagingError: in user code:

    /home/vladimir/anaconda3/envs/effdet_tf/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py:1478 predict_function  *
        return step_function(self, iterator)
    /home/vladimir/workspace/EfficientDet/model.py:351 call  *
        feature = self.bns[i][self.level](feature)
    /home/vladimir/anaconda3/envs/effdet_tf/lib/python3.7/site-packages/tensorflow/python/training/tracking/data_structures.py:380 __getitem__
        return self._storage[key]

    IndexError: list index out of range
ben-kraus commented 3 years ago

I get the same error on predict on single image. I guess it is a TF2.4 issue, since I had it working on TF2.3

dheera commented 3 years ago

I get the same error above on 2.4. On 2.3 I get this instead

Traceback (most recent call last):
  File "inference.py", line 63, in <module>
    main()
  File "inference.py", line 26, in main
    _, model = efficientdet(phi=phi,
  File "/home/dheera/Dropbox/code/EfficientDet/model.py", line 443, in efficientdet
    classification = [class_net([feature, i]) for i, feature in enumerate(fpn_features)]
  File "/home/dheera/Dropbox/code/EfficientDet/model.py", line 443, in <listcomp>
    classification = [class_net([feature, i]) for i, feature in enumerate(fpn_features)]
  File "/home/dheera/venv/tf2.3/lib/python3.8/site-packages/tensorflow/python/keras/engine/base_layer.py", line 924, in __call__
    if _in_functional_construction_mode(self, inputs, args, kwargs, input_list):
  File "/home/dheera/venv/tf2.3/lib/python3.8/site-packages/tensorflow/python/keras/engine/base_layer.py", line 3223, in _in_functional_construction_mode
    raise ValueError('It appears you are trying to construct a '
ValueError: It appears you are trying to construct a functional model, but not all of the inputs in the first positional argument of your layer call are symbolic tensors. (Input objects, or the output of another layer) Functional models cannot correctly track custom layers unless all values in the first call argument are symbolic.
stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.