Exemplo n.º 1
0
def run_training_with_my_data(step_num, keep_prob):
    # file_dir = 'local_data/'
    # image, label = get_files(file_dir)
    # image_batches, label_batches = get_batches(image, label,
    #                                            resize_w=28, resize_h=28, batch_size=2, capacity=20)

    input_new = ild.InputLocalData('local_data/')
    image_batches, label_batches = input_new.get_batches(28, 28, 2, 20)

    print(label_batches)

    logits = cnn_model(image_batches, keep_prob=keep_prob, first_w="w_conv1")
    loss = get_loss(logits, label_batches)

    train_step = training(loss)
    acc = get_accuracy(logits, label_batches)

    init = tf.global_variables_initializer()
    session.run(init)

    coord = tf.train.Coordinator()
    threads = tf.train.start_queue_runners(sess=session, coord=coord)

    try:
        for step in np.arange(step_num):
            print("run_training: step %d" % step)
            if coord.should_stop():
                break
            _, train_acc, train_loss = session.run([train_step, acc, loss])
            print("loss:{} , accuracy:{}".format(train_loss, train_acc))
    except tf.errors.OutOfRangeError:
        print("Done!!!")
    finally:
        coord.request_stop()
    coord.join(threads)
Exemplo n.º 2
0
"""
主函数
"""
import numpy as np
import tensorflow as tf
import input_local_data as ild
import training_graph as tg
import args_manager as am

session = tf.InteractiveSession()

# --------------------------------- build a graph -- start -------------------------------

args = am.ArgumentManager("model_save/cnn.ckpt", session)

input_data = ild.InputLocalData('local_data/')
img_batch, lab_batch = input_data.get_batches(resize_w=28, resize_h=28,
                                              batch_size=5, capacity=20)

graph = tg.TrainingGraph(channels=3, keep_prob=1, classNum=10)
train_step, acc = graph.build_graph_with_batch(img_batch, lab_batch)

# --------------------------------- build a graph -- end -------------------------------

# init all variables
ys = input("attention!!!\n    restore the variables? (y/n)\n")
if ys == 'y':
    args.restore()
else:
    init = tf.global_variables_initializer()
    session.run(init)