在验证VOC2007测试集时
1. 首先将数据集转换为tfrecord格式:
DATASET_DIR=./VOC2007/test/ OUTPUT_DIR=./tfrecords python tf_convert_data.py \ --dataset_name=pascalvoc \ --dataset_dir=${DATASET_DIR} \ --output_name=voc_2007_test \ --output_dir=${OUTPUT_DIR}
调用tf_convert_data.py将test set转化成tfrecoeds:(注意:这里直接运行会碰到无法读取图片,UTF-8无法decode的Erro,解决办法是打开SSD工程—>datasets—>pascalvoc_to_tfrecords.py 。。。然后更改文件的83行读取方式为’rb’)
注意将voc_2007_train改为voc_2007_test。
2. 进行模型评估:
DATASET_DIR=./tfrecords
EVAL_DIR=./logs/ CHECKPOINT_PATH=./checkpoints/ssd_300_vgg.ckpt python eval_ssd_network.py \ --eval_dir=${EVAL_DIR} \ --dataset_dir=${DATASET_DIR} \ --dataset_name=pascalvoc_2007 \ --dataset_split_name=test \ --model_name=ssd_300_vgg \ --checkpoint_path=${CHECKPOINT_PATH} \ --batch_size=
运行以上代码报错:
TypeError: Can not convert a tuple into a Tensor or Operation.解决方法:
打开eval_ssd_network.py文件,然后加入以下代码:
下面两处地方调用:
- def flatten(x):
- result = []
- for el in x:
- if isinstance(el, tuple):
- result.extend(flatten(el))
- else:
- result.append(el)
- return result
- # Standard evaluation loop.
- start = time.time()
- slim.evaluation.evaluate_once(
- master=FLAGS.master,
- checkpoint_path=checkpoint_path,
- logdir=FLAGS.eval_dir,
- num_evals=num_batches,
- eval_op=flatten(list(names_to_updates.values())), #这里也调用flatten
- variables_to_restore=variables_to_restore,
- session_config=config)
2 训练自己的数据集:
- # Waiting loop.
- slim.evaluation.evaluation_loop(
- master=FLAGS.master,
- checkpoint_dir=checkpoint_path,
- logdir=FLAGS.eval_dir,
- num_evals=num_batches,
- eval_op=flatten(list(names_to_updates.values())), #这里调用flatten
- variables_to_restore=variables_to_restore,
- eval_interval_secs=60,
- max_number_of_evaluations=np.inf,
- session_config=config,
- timeout=None
voc格式的数据集制作好以后,转换成tfrecords。需要修改一下源码,
datasets\pascalvoc_common.py:
#VOC_LABELS = { # 'none': (0, 'Background'), # 'aeroplane': (1, 'Vehicle'), # 'bicycle': (2, 'Vehicle'), # 'bird': (3, 'Animal'), # 'boat': (4, 'Vehicle'), # 'bottle': (5, 'Indoor'), # 'bus': (6, 'Vehicle'), # 'car': (7, 'Vehicle'), # 'cat': (8, 'Animal'), # 'chair': (9, 'Indoor'), # 'cow': (10, 'Animal'), # 'diningtable': (11, 'Indoor'), # 'dog': (12, 'Animal'), # 'horse': (13, 'Animal'), # 'motorbike': (14, 'Vehicle'), # 'person': (15, 'Person'), # 'pottedplant': (16, 'Indoor'), # 'sheep': (17, 'Animal'), # 'sofa': (18, 'Indoor'), # 'train': (19, 'Vehicle'), # 'tvmonitor': (20, 'Indoor'), #} VOC_LABELS = { 'none': (0, 'Background'), 'crazing': (1, 'crazing'), 'inclusion': (2, 'inclusion'), 'patches': (3, 'patches'), 'pitted_surface': (4, 'pitted_surface'), 'rolled-in_scale': (5, 'rolled-in_scale'), 'scratches': (6, 'scratches'), }
接着跳转到SSD-tensorflow目录下,进行tfrecords操作,我的运行命令如下:
- DATASET_DIR=VOCtest2018/
- OUTPUT_DIR=tfrecords/
- python3 tf_convert_data.py \
- --dataset_name=pascalvoc \
- --dataset_dir=${DATASET_DIR} \
- --output_name=voc_2007_train \
- --output_dir=${OUTPUT_DIR}
这样就可以进行训练了,运行的命令为:
- DATASET_DIR=tfrecords
- TRAIN_DIR=logs/
- CHECKPOINT_PATH=./checkpoints/ssd_300_vgg.ckpt
- python3 train_ssd_network.py \
- --train_dir=${TRAIN_DIR} \
- --dataset_dir=${DATASET_DIR} \
- --dataset_name=pascalvoc_2007 \
- --dataset_split_name=train \
- --model_name=ssd_300_vgg \
- --checkpoint_path=${CHECKPOINT_PATH} \
- --save_summaries_secs=60 \
- --save_interval_secs=600 \
- --weight_decay=0.0005 \
- --optimizer=adam \
- --learning_rate=0.001 \
- --batch_size=16
- --device=cpu(如果在cpu机器上跑)
- --data_format=NHWC(针对cpu,或者在train_ssd_network中第27行代码改)
博主您好,请问类别不同时是否需要修改ckpt文件,现在直接加载ssd_vgg_300.ckpt会提示"Restoring from checkpoint failed. This is most likely due to a Variable name or other graph key that is missing from the checkpoint." 不知博主是否遇到这样的错误提示?期待您的回复!非常感谢!
回复删除