在学习《21个项目玩转深度学习》这本书时,第三章使用TensorFlow Slim微调模型遇上了一个问题。
运行:
python train_image_classifier.py \
--train_dir=satellite/train_dir \
--dataset_name=satellite \
--dataset_split_name=train \
--dataset_dir=satellite/data \
--model_name=inception_v3 \
--checkpoint_path=satellite/pretrained/inception_v3.ckpt \
--checkpoint_exclude_scopes=InceptionV3/Logits,InceptionV3/AuxLogits \
--trainable_scopes=InceptionV3/Logits,InceptionV3/AuxLogits \
--max_number_of_steps=100000 \
--batch_size=32 \
--learning_rate=0.001 \
--learning_rate_decay_type=fixed \
--save_interval_secs=300 \
--save_summaries_secs=2 \
--log_every_n_steps=10 \
--optimizer=rmsprop \
--weight_decay=0.00004
出现下面问题:
图可能不清楚,说说这个的主要问题:
E:\Anaconda3\lib\site-packages\h5py__init__.py:34: FutureWarning: Conversion of the second argument of issubdtype from
float
tonp.floating
is deprecated. In future, it will be treated asnp.float64 == np.dtype(float).type
.
从上面错误的提示,可以看出这是问题是因为h5py这包有问题,到底是什么问题呢?
其实,就是包的版本低了。使用下面pip升级:
pip install h5py==2.8.0rc1
升级之后,我们再次运行,结果又出错了。这次是:
从图中画红框的位置可以看到一个关键的词“GPU”,这就是问题所在。如果没有安装GPU版的TensorFlow,那么我们得加一个参数:–clone_on_cpu。将这参数设为True,这将使用cpu进行训练。
python train_image_classifier.py \
--train_dir=satellite/train_dir \
--dataset_name=satellite \
--dataset_split_name=train \
--dataset_dir=satellite/data \
--model_name=inception_v3 \
--checkpoint_path=satellite/pretrained/inception_v3.ckpt \
--checkpoint_exclude_scopes=InceptionV3/Logits,InceptionV3/AuxLogits \
--trainable_scopes=InceptionV3/Logits,InceptionV3/AuxLogits \
--max_number_of_steps=100000 \
--batch_size=32 \
--learning_rate=0.001 \
--learning_rate_decay_type=fixed \
--save_interval_secs=300 \
--save_summaries_secs=2 \
--log_every_n_steps=10 \
--optimizer=rmsprop \
--weight_decay=0.00004 \
--clone_on_cpu=True
这样运行就OK了!