Exemplo n.º 1
0
def LeNet_test():
    # initializing the network
    network = LeNet(BATCH_SIZE)
    network.getTheParas(MODEL_FILE)

    # load the test data
    _, _, test_imgs, _, _, test_label = util.load_data(MNIST_PATH, False)

    log_string('------------start test-----------')

    num_batch = test_imgs.shape[0] // BATCH_SIZE
    start = 0
    end = start + BATCH_SIZE
    loss = 0.0
    total_correct = 0.0
    total_seen = 0
    for n in range(num_batch):
        log_string('--------{}/{}(batchs) completed!'.format(n + 1, num_batch))
        current_img = test_imgs[start:end, ...]
        current_label = test_label[start:end, ...]
        start = end
        end += BATCH_SIZE
        predict_val, loss_val = network.forward(current_img, current_label)
        correct = np.sum(predict_val == current_label)
        total_correct += correct
        loss += loss_val
        total_seen += BATCH_SIZE
    log_string('eval mean loss: {}'.format(loss / num_batch))
    log_string('eval accuracy: {}'.format(total_correct / total_seen))
Exemplo n.º 2
0
def inference():
    # initializing the network
    network = LeNet(BATCH_SIZE)
    network.getTheParas(MODEL_FILE)
    print(IMAGE_PATH)
    image_paths = glob.glob(os.path.join(IMAGE_PATH, '*'))

    for image_path in image_paths:
        image_data = cv2.imread(image_path, 0)
        image_data = image_data[newaxis, :, :, newaxis]
        predict_val = network.inference(image_data)
        print(image_path, ':', predict_val[0][0])