Tflite-model-maker training error (custom object detection)

Hi, I’ve tried to train custom object detection model via tflite-model-makers referred to @khanhlvg 's Train a custom object detection model using your data

Unfortunately, I met the following error, and I don’t know how to solve it. Is there anyone who can give me the Christmas present?

InvalidArgumentError: 2 root error(s) found.
  (0) INVALID_ARGUMENT:  assertion failed: [ERROR: please increase config.max_instances_per_image] [Condition x < y did not hold element-wise:] [x (parser/strided_slice_17:0) = ] [129] [y (parser/assert_less/y:0) = ] [100]
	 [[{{node parser/assert_less/Assert/Assert}}]]
	 [[MultiDeviceIteratorGetNextFromShard]]
	 [[RemoteCall]]
	 [[IteratorGetNext]]
	 [[batch_cls_loss/write_summary/summary_cond/then/_4138/batch_cls_loss/write_summary/ReadVariableOp/_94]]
  (1) INVALID_ARGUMENT:  assertion failed: [ERROR: please increase config.max_instances_per_image] [Condition x < y did not hold element-wise:] [x (parser/strided_slice_17:0) = ] [129] [y (parser/assert_less/y:0) = ] [100]
	 [[{{node parser/assert_less/Assert/Assert}}]]
	 [[MultiDeviceIteratorGetNextFromShard]]
	 [[RemoteCall]]
	 [[IteratorGetNext]]

I googled and found this issue but I have no I idea how i use it on TF lite model maker env.

You need to pass the max instance number as an hparam when the model is created. Set the MAXOBJECTCOUNT slightly higher than the max number of objects you expect to see in an image.

from tflite_model_maker import object_detector
object_detector.EfficientDetLite0Spec(hparams {'max_instances_per_image': MAXOBJECTCOUNT})

All kinds of model parameters can be tweaked using the hyper params dictionary.

You can read more about them here.

Thnanks @dylan

Unfortunately, I set the MAXOBJECTCOUNT to 8000 but it occurred same error.

It resolved! I modified the code to this

# instead of spec = model_spec.get('efficientdet_lite0')

spec = object_detector.EfficientDetSpec(
  model_name='efficientdet-lite0', 
  uri='https://tfhub.dev/tensorflow/efficientdet/lite0/feature-vector/1', 
  hparams={'max_instances_per_image': 8000})

That pass the hyperparameters directly and this worked successfully

1 Like

Glad it actually worked out for you! :slight_smile:

1 Like

This worked for me. I have a model with 1 class with multiple (hundreds) of occourrences on a picture

Worked for me as well, thanks