I was using Tensorflow 2.2 in Colab and planning to train ResNet50 SSD model from scratch.
I was writing a function to extract the number of classes from self-created label map pbtxt file. Then when I tried to run the function, it reported the import error.
Here is the content of the label_map.pbtxt file:
item {
id: 1
name: 'apple'
}
item {
id: 2
name: 'banana'
}
item {
id: 3
name: 'orange'
}
When I ran:
num_classes = get_num_classes('label_map.pbtxt')
The following error appears:
/usr/local/lib/python3.7/dist-packages/tensorflow/_api/v2/compat/v1/compat/v1/init.py in ()
158 from tensorflow.python.framework.ops import container
159 from tensorflow.python.framework.ops import control_dependencies
--> 160 from tensorflow.python.framework.ops import convert_to_tensor_v1_with_dispatch as convert_to_tensor
161 from tensorflow.python.framework.ops import device
162 from tensorflow.python.framework.ops import disable_eager_execution
ImportError: cannot import name 'convert_to_tensor_v1_with_dispatch' from 'tensorflow.python.framework.ops' (/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/ops.py)
4. Expected behavior
I expect the function to return 3 in this case.
5. Additional context
Include any logs that would be helpful to diagnose the problem.
6. System information
OS Platform and Distribution (e.g., Linux Ubuntu 16.04):
Mobile device name if the issue happens on a mobile device:
TensorFlow installed from (source or binary):
TensorFlow version (use command below): v2.2.0-rc4-8-g2b96f3662b 2.2.0
Prerequisites
Please answer the following questions for yourself before submitting an issue.
1. The entire URL of the file you are using
https://github.com/tensorflow/models/tree/master/research/object_detection/utils
2. Describe the bug
I was using Tensorflow 2.2 in Colab and planning to train ResNet50 SSD model from scratch.
I was writing a function to extract the number of classes from self-created label map pbtxt file. Then when I tried to run the function, it reported the import error.
3. Steps to reproduce
Here is the code for the function:
def get_num_classes(pbtxt_fname): from object_detection.utils import label_map_util label_map = label_map_util.load_labelmap(pbtxt_fname) categories = label_map_util.convert_label_map_to_categories( label_map, max_num_classes=90, use_display_name=True) category_index = label_map_util.create_category_index(categories) return len(category_index.keys())
Here is the content of the label_map.pbtxt file: item { id: 1 name: 'apple' }
item { id: 2 name: 'banana' }
item { id: 3 name: 'orange' }
When I ran: num_classes = get_num_classes('label_map.pbtxt')
The following error appears:
/usr/local/lib/python3.7/dist-packages/tensorflow/_api/v2/compat/v1/compat/v1/init.py in()
158 from tensorflow.python.framework.ops import container
159 from tensorflow.python.framework.ops import control_dependencies
--> 160 from tensorflow.python.framework.ops import convert_to_tensor_v1_with_dispatch as convert_to_tensor
161 from tensorflow.python.framework.ops import device
162 from tensorflow.python.framework.ops import disable_eager_execution
ImportError: cannot import name 'convert_to_tensor_v1_with_dispatch' from 'tensorflow.python.framework.ops' (/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/ops.py)
4. Expected behavior
I expect the function to return 3 in this case.
5. Additional context
Include any logs that would be helpful to diagnose the problem.
6. System information