model_main_tf2.py issues with training object detection model
@Maxwell12345,
Could you please confirm whether you are trying to execute the below code or the different one?
https://github.com/tensorflow/models/blob/master/research/object_detection/model_main_tf2.py

Thank you! This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you. This issue was closed because it has been inactive for 7 days since being marked as stale. Please reopen if you'd like to work on this further. Are you satisfied with the resolution of your issue?
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=Yes&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/62063">Yes</a>
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=No&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/62063">No</a>

### Issue type

Bug

### Have you reproduced the bug with TensorFlow Nightly?

Yes

### Source

source

### TensorFlow version

2.8

### Custom code

No

### OS platform and distribution

Google Colab

### Mobile device

_No response_

### Python version

3.9

### Bazel version

_No response_

### GCC/compiler version

_No response_

### CUDA/cuDNN version

_No response_

### GPU model and memory

_No response_

### Current behavior?

The tf_slim module class tfexample_decode.py at line 453 calls control_flow_ops.case 
There is no "case" attribute to control_flow_ops

### Standalone code to reproduce the issue

```shell
Google Colab, SSD Moblenet v2 graph, tfrecords
```


### Relevant log output

```shell
I1007 00:12:20.542787 134709293735936 dataset_builder.py:162] Reading unweighted datasets: ['.../train.record']
INFO:tensorflow:Reading record datasets for input file: ['.../train/train.record']
I1007 00:12:20.543272 134709293735936 dataset_builder.py:79] Reading record datasets for input file: ['.../train.record']
INFO:tensorflow:Number of filenames to read: 1
I1007 00:12:20.543381 134709293735936 dataset_builder.py:80] Number of filenames to read: 1
WARNING:tensorflow:num_readers has been reduced to 1 to match input file shards.
W1007 00:12:20.543440 134709293735936 dataset_builder.py:86] num_readers has been reduced to 1 to match input file shards.
WARNING:tensorflow:From /content/models/research/./object_detection/builders/dataset_builder.py:100: parallel_interleave (from tensorflow.python.data.experimental.ops.interleave_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.data.Dataset.interleave(map_func, cycle_length, block_length, num_parallel_calls=tf.data.AUTOTUNE)` instead. If sloppy execution is desired, use `tf.data.Options.deterministic`.
W1007 00:12:20.550345 134709293735936 deprecation.py:50] From /content/models/research/./object_detection/builders/dataset_builder.py:100: parallel_interleave (from tensorflow.python.data.experimental.ops.interleave_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.data.Dataset.interleave(map_func, cycle_length, block_length, num_parallel_calls=tf.data.AUTOTUNE)` instead. If sloppy execution is desired, use `tf.data.Options.deterministic`.
WARNING:tensorflow:From /content/models/research/./object_detection/builders/dataset_builder.py:235: DatasetV1.map_with_legacy_function (from tensorflow.python.data.ops.dataset_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.data.Dataset.map()
W1007 00:12:20.572327 134709293735936 deprecation.py:50] From /content/models/research/./object_detection/builders/dataset_builder.py:235: DatasetV1.map_with_legacy_function (from tensorflow.python.data.ops.dataset_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.data.Dataset.map()
Traceback (most recent call last):
  File "/content/models/research/object_detection/model_main_tf2.py", line 116, in <module>
    tf.compat.v1.app.run()
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/platform/app.py", line 36, in run
    _run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef)
  File "/usr/local/lib/python3.10/dist-packages/absl/app.py", line 308, in run
    _run_main(main, args)
  File "/usr/local/lib/python3.10/dist-packages/absl/app.py", line 254, in _run_main
    sys.exit(main(argv))
  File "/content/models/research/object_detection/model_main_tf2.py", line 107, in main
    model_lib_v2.train_loop(
  File "/content/models/research/./object_detection/model_lib_v2.py", line 563, in train_loop
    train_input = strategy.experimental_distribute_datasets_from_function(
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/util/deprecation.py", line 383, in new_func
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/distribute/distribute_lib.py", line 1563, in experimental_distribute_datasets_from_function
    return self.distribute_datasets_from_function(dataset_fn, options)
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/distribute/distribute_lib.py", line 1554, in distribute_datasets_from_function
    return self._extended._distribute_datasets_from_function(  # pylint: disable=protected-access
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/distribute/mirrored_strategy.py", line 613, in _distribute_datasets_from_function
    return input_util.get_distributed_datasets_from_function(
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/distribute/input_util.py", line 144, in get_distributed_datasets_from_function
    return input_lib.DistributedDatasetsFromFunction(
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/distribute/input_lib.py", line 1143, in __init__
    self.build()
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/distribute/input_lib.py", line 1165, in build
    _create_datasets_from_function_with_input_context(
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/distribute/input_lib.py", line 1680, in _create_datasets_from_function_with_input_context
    dataset = dataset_fn(ctx)
  File "/content/models/research/./object_detection/model_lib_v2.py", line 554, in train_dataset_fn
    train_input = inputs.train_input(
  File "/content/models/research/./object_detection/inputs.py", line 908, in train_input
    dataset = INPUT_BUILDER_UTIL_MAP['dataset_build'](
  File "/content/models/research/./object_detection/builders/dataset_builder.py", line 250, in build
    dataset = dataset_map_fn(dataset, decoder.decode, batch_size,
  File "/content/models/research/./object_detection/builders/dataset_builder.py", line 235, in dataset_map_fn
    dataset = dataset.map_with_legacy_function(
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/util/deprecation.py", line 383, in new_func
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/data/ops/dataset_ops.py", line 4128, in map_with_legacy_function
    return map_op._map_v1_with_legacy_function(
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/data/ops/map_op.py", line 85, in _map_v1_with_legacy_function
    _ParallelMapDataset(
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/data/ops/map_op.py", line 148, in __init__
    self._map_func = structured_function.StructuredFunctionWrapper(
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/data/ops/structured_function.py", line 272, in __init__
    self._function.add_to_graph(ops.get_default_graph())
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/framework/function.py", line 579, in add_to_graph
    self._create_definition_if_needed()
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/framework/function.py", line 412, in _create_definition_if_needed
    self._create_definition_if_needed_impl()
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/framework/function.py", line 430, in _create_definition_if_needed_impl
    temp_graph = func_graph_from_py_func(
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/framework/function.py", line 1007, in func_graph_from_py_func
    outputs = func(*func_graph.inputs)
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/data/ops/structured_function.py", line 178, in wrapped_fn
    ret = wrapper_helper(*args)
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/data/ops/structured_function.py", line 161, in wrapper_helper
    ret = autograph.tf_convert(self._func, ag_ctx)(*nested_args)
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/autograph/impl/api.py", line 693, in wrapper
    raise e.ag_error_metadata.to_exception(e)
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/autograph/impl/api.py", line 690, in wrapper
    return converted_call(f, args, kwargs, options=options)
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/autograph/impl/api.py", line 439, in converted_call
    result = converted_f(*effective_args, **kwargs)
  File "/tmp/__autograph_generated_fileqkyio7wq.py", line 74, in tf__decode
    tensors = ag__.converted_call(ag__.ld(decoder).decode, (ag__.ld(serialized_example),), dict(items=ag__.ld(keys)), fscope)
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/autograph/impl/api.py", line 439, in converted_call
    result = converted_f(*effective_args, **kwargs)
  File "/tmp/__autograph_generated_file1opxbxnu.py", line 81, in tf__decode
    ag__.for_stmt(ag__.ld(items), None, loop_body_1, get_state_3, set_state_3, (), {'iterate_names': 'item'})
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/autograph/operators/control_flow.py", line 449, in for_stmt
    for_fn(iter_, extra_test, body, get_state, set_state, symbol_names, opts)
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/autograph/operators/control_flow.py", line 500, in _py_for_stmt
    body(target)
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/autograph/operators/control_flow.py", line 466, in protected_body
    original_body(protected_iter)
  File "/tmp/__autograph_generated_file1opxbxnu.py", line 77, in loop_body_1
    ag__.converted_call(ag__.ld(outputs).append, (ag__.converted_call(ag__.ld(handler).tensors_to_item, (ag__.ld(keys_to_tensors),), None, fscope),), None, fscope)
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/autograph/impl/api.py", line 441, in converted_call
    result = converted_f(*effective_args)
  File "/tmp/__autograph_generated_fileok5ldq7m.py", line 39, in tf__tensors_to_item
    ag__.if_stmt(ag__.ld(self)._repeated, if_body, else_body, get_state, set_state, ('do_return', 'retval_'), 2)
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/autograph/operators/control_flow.py", line 1217, in if_stmt
    _py_if_stmt(cond, body, orelse)
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/autograph/operators/control_flow.py", line 1270, in _py_if_stmt
    return body() if cond else orelse()
  File "/tmp/__autograph_generated_fileok5ldq7m.py", line 35, in else_body
    retval_ = ag__.converted_call(ag__.ld(self)._decode, (ag__.ld(image_buffer), ag__.ld(image_format)), None, fscope)
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/autograph/impl/api.py", line 441, in converted_call
    result = converted_f(*effective_args)
  File "/tmp/__autograph_generated_fileubbeey9m.py", line 80, in tf___decode
    image = ag__.converted_call(ag__.ld(control_flow_ops).case, (ag__.ld(pred_fn_pairs),), dict(default=ag__.ld(check_jpeg), exclusive=True), fscope)
AttributeError: in user code:

    File "/content/models/research/./object_detection/data_decoders/tf_example_decoder.py", line 556, in decode  *
        tensors = decoder.decode(serialized_example, items=keys)
    File "/usr/local/lib/python3.10/dist-packages/tf_slim/data/tfexample_decoder.py", line 723, in decode  *
        outputs.append(handler.tensors_to_item(keys_to_tensors))
    File "/usr/local/lib/python3.10/dist-packages/tf_slim/data/tfexample_decoder.py", line 406, in tensors_to_item  *
        return self._decode(image_buffer, image_format)
    File "/usr/local/lib/python3.10/dist-packages/tf_slim/data/tfexample_decoder.py", line 454, in _decode  *
        image = control_flow_ops.case(

    AttributeError: module 'tensorflow.python.ops.control_flow_ops' has no attribute 'case'
```
