示例#1
0
    # Standardize data to have feature values between 0 and 1.
    train_x = train_x_flatten / 255.
    test_x = test_x_flatten / 255.

    return train_x, test_x, train_y, test_y, classes, num_px


if __name__ == "__main__":
    layers_dims = [12288, 20, 10, 1]  #  4-layer model
    m = Main(layers_dims)

    train_x, test_x, train_y, test_y, classes, num_px = preprocessing()
    parameters = m.L_layer_model(train_x,
                                 train_y,
                                 layers_dims,
                                 num_epochs=5000,
                                 print_cost=True,
                                 lambd=0,
                                 learning_rate=0.001)
    pred_train = m.predict(train_x, train_y, parameters)
    pred_test = m.predict(test_x, test_y, parameters)

    my_image = "cat.jpg"
    my_label_y = [1]  # the true class of your image (1 -> cat, 0 -> non-cat)

    fname = "images/" + my_image
    image = np.array(plt.imread(fname))
    my_image = ((np.array(
        Image.fromarray(image).resize((num_px, num_px),
                                      Image.ANTIALIAS)).reshape(
                                          (1, num_px * num_px * 3)))).T
示例#2
0
    test_x_flatten = test_x_orig.reshape(test_x_orig.shape[0], -1).T
    num_px = train_x_orig.shape[1]
    # Standardize data to have feature values between 0 and 1.
    train_x = train_x_flatten / 255.
    test_x = test_x_flatten / 255.

    return train_x, test_x, train_y, test_y, classes, num_px


if __name__ == "__main__":
    layers_dims = [12288, 20, 7, 5, 1]  #  5-layer model
    m = Main(layers_dims)
    train_x, test_x, train_y, test_y, classes, num_px = preprocessing()
    parameters = m.L_layer_model(train_x,
                                 train_y,
                                 layers_dims,
                                 num_iterations=2500,
                                 print_cost=True)
    pred_train = m.predict(train_x, train_y, parameters)
    pred_test = m.predict(test_x, test_y, parameters)

    my_image = "cat.jpg"
    my_label_y = [1]  # the true class of your image (1 -> cat, 0 -> non-cat)

    fname = "images/" + my_image
    image = np.array(plt.imread(fname))
    my_image = ((np.array(
        Image.fromarray(image).resize((num_px, num_px),
                                      Image.ANTIALIAS)).reshape(
                                          (1, num_px * num_px * 3)))).T