def main(flags):
# ???????
ds = mnist.Data(flags.directory)
# tensorflow ??
config = tf.ConfigProto()
config.gpu_options.allow_growth = True
# ??session
with tf.Session(config=config) as session:
# ??????
model = Model('Model',
session,
flags.height,
flags.width,
flags.depth,
flags.feature_size,
flags.num_classes).build()
# ??slot
train = model.get_slot('train')
predict = model.get_slot('predict')
# ?????
session.run(tf.global_variables_initializer())
# ????
for i in range(1, flags.nloop + 1):
# ????batch???
images_batch, labels_batch = ds.next_batch(flags.bsize)
loss, train_accuracy = train(images_batch, labels_batch, 0.5)
# ?100?????????????batch??accuracy
if i % 100 == 0:
print('Loop {}:\tloss={}\ttrain accuracy={}'.format(i, loss, train_accuracy))
# ????????accuracy
accuracy = predict(ds.test_images, ds.test_labels, 1.0)
print('Accuracy on test set: {}'.format(accuracy))
return 0
评论列表
文章目录