python - 如何在 Tensorflow 中使用 COCO 对象检测数据集?
问题描述
我对对象检测和 TensorFlow 这个主题非常陌生,我想知道如何将这个文件加载为 TensorFlow 数据集?我使用 pandas 将其作为 DataFrame 读取,但无法将其解析为 TensorFlow 数据集。我试过这个
train_ds = tf.data.Dataset.from_tensor_slices(
(
tf.cast(dataframe['file'].values, tf.string),
tf.cast(dataframe['width'].values, tf.int8),
tf.cast(dataframe['height'].values, tf.int8)
),
(
# tf.cast(dataframe['annotations'].values, tf.string)
# here I want to cast the annotations to the dataset but I don't
# know how
)
)
但无法弄清楚如何让注释在这里工作......有什么帮助吗?
解决方案
看起来您的数据是 JSON 格式,直接使用tf.io.decode_json_example
库来读取 json 值。
import tensorflow as tf
tf.io.decode_json_example([
[example_json, example_json],
[example_json, example_json]]).shape.as_list()
有关该库的更多详细信息,请参见此处。