从 None 引发 core._status_to_exception(e) tensorflow.python.framework.errors_impl.InvalidArgumentError:

问题描述 投票:0回答:1

尝试按照本教程在 Citypersons 数据集上训练对象检测模型。 https://neptune.ai/blog/how-to-train-your-own-object- detector-using-tensorflow-object-detection-api

我运行以下命令:

python model_main_tf2.py --pipeline_config_path=models/MaskCNN/v1/pipeline.config --  model_dir=models/MaskCNN/v1/  --checkpoint_every_n=4  --num_workers=2  --alsologtostderr

并出现以下错误:

File "/Users/Desktop/TensorFlow/tf2_api_env/lib/python3.7/site-packages/tensorflow/python/framework/ops.py", line 7215, in raise_from_not_ok_status
raise core._status_to_exception(e) from None  # pylint: disable=protected-access
tensorflow.python.framework.errors_impl.InvalidArgumentError: {{function_node __wrapped__IteratorGetNext_output_types_18_device_/job:localhost/replica:0/task:0/device:CPU:0}} indices[0] = 0 is not in [0, 0)
     [[{{node GatherV2_7}}]]
     [[MultiDeviceIteratorGetNextFromShard]]
     [[RemoteCall]] [Op:IteratorGetNext]

我对此相当陌生,无法找出问题所在,任何帮助将不胜感激。 谢谢。

tensorflow object-detection-api
1个回答
0
投票

当我尝试从 Roboflow 导出的数据集

efficientDet-object-detection
训练
tfrecord
模型时,我遇到了同样的问题。这是我解决这个问题的方法:

此错误意味着您生成的

tf-record
文件已损坏。使用以下脚本检查
tf-records
的状态:

import tensorflow as tf

def is_tfrecord_corrupted(tfrecord_file):
    try:
        for record in tf.data.TFRecordDataset(tfrecord_file):
            # Attempt to parse the record
            _ = tf.train.Example.FromString(record.numpy())
    except tf.errors.DataLossError as e:
        print(f"DataLossError encountered: {e}")
        return True
    except Exception as e:
        print(f"An error occurred: {e}")
        return True
    return False

# Replace with your TFRecord file paths 
tfrecord_files = ['your_test_record_fname', 'your_train_record_fname']

for tfrecord_file in tfrecord_files:
  if is_tfrecord_corrupted(tfrecord_file):
      print(f"The TFRecord file {tfrecord_file} is corrupted.")
  else:
      print(f"The TFRecord file {tfrecord_file} is fine.")

为了修复损坏的

tfrecords
,我将数据集导出为
pascal-voc
格式,然后编写了托管在 GitHub 上的以下脚本,以从
tfrecords
格式化数据集生成新的
pascal-voc

生成新
tfrecords
的脚本在这里:https://github.com/arrafi-musabbir/license-plate-detection-recognition/blob/main/generate_tfrecord.py

  • 根据您的数据集创建您自己的
    label-map-pbtxt
label_path = "your label_map.pbtxt path"

# modify according to your dataset class names
labels = [{'name':'license', 'id':1}]

with open(label_path, 'w') as f:
    for label in labels:
        f.write('item { \n')
        f.write('\tname:\'{}\'\n'.format(label['name']))
        f.write('\tid:{}\n'.format(label['id']))
        f.write('}\n')
  • 按以下方式运行脚本:
python generate_tfrecord.py -x {train_dir_path} -l {labelmap_path} -o {new_train_record_path}
python generate_tfrecord.py -x {valid_dir_path} -l {labelmap_path} -o {new_valid_record_path}
python generate_tfrecord.py -x {test_dir_path} -l {labelmap_path} -o {new_test_record_path}

之后,再次运行

is_tfrecord_corrupted(tfrecord_file)
,你会看到
tfrecords
没问题了。

© www.soinside.com 2019 - 2024. All rights reserved.