<p>随着评论和建议以及参数的调整,以下是对我有用的结果。在</p>
<p>启动张力板、训练模型等的代码。使用-表示笔记本单元</p>
<hr/>
<pre><code>%%bash
# clean model output dirs
# This is so that the trained model is deleted
output_dir=${PWD}/${TRAINING_DIR}
echo ${output_dir}
rm -rf ${output_dir}
</code></pre>
<hr/>
^{pr2}$
<hr/>
<pre><code>%%bash
# The model run config is hard coded to checkpoint every 500 steps
#
#echo ${PYTHONPATH}:${PWD}/${MODEL_NAME}
export PYTHONPATH=${PYTHONPATH}:${PWD}/${MODEL_NAME}
python -m trainer.task \
train_data_paths="${PWD}/samples/train_sounds*" \
eval_data_paths=${PWD}/samples/valid_sounds.csv \
output_dir=${PWD}/${TRAINING_DIR} \
hidden_units="175" \
train_batch_size=10 \
eval_batch_size=100 \
eval_steps=1000 \
min_eval_frequency=15 \
train_steps=20000 job-dir=./tmp
</code></pre>
<p>相关型号代码</p>
<pre><code># This hard codes the checkpoints to be
# every 500 training steps?
estimator = tf.estimator.DNNClassifier(
model_dir = model_dir,
feature_columns = final_columns,
hidden_units=hidden_units,
config=tf.estimator.RunConfig(save_checkpoints_steps=500),
n_classes=2)
# trainspec to tell the estimator how to get training data
train_spec = tf.estimator.TrainSpec(
input_fn = read_dataset(
filename = args['train_data_paths'],
mode = tf.estimator.ModeKeys.TRAIN, # make sure you use the dataset api
batch_size = args['train_batch_size']),
max_steps = args['train_steps']) # max_steps allows a resume
exporter = tf.estimator.LatestExporter(name = 'exporter',
serving_input_receiver_fn = serving_input_fn)
eval_spec = tf.estimator.EvalSpec(
input_fn = read_dataset(
filename = args['eval_data_paths'],
mode = tf.estimator.ModeKeys.EVAL,
batch_size = args['eval_batch_size']),
steps=args['eval_steps'],
throttle_secs = args['min_eval_frequency'],
exporters = exporter)
tf.estimator.train_and_evaluate(estimator, train_spec, eval_spec)
</code></pre>
<p>结果图</p>
<p><a href="https://i.stack.imgur.com/Lr5w4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Lr5w4.png" alt="enter image description here"/></a>
<a href="https://i.stack.imgur.com/QjZVj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QjZVj.png" alt="enter image description here"/></a></p>