예제 #1
0
def get_data_info():
    """
    加载上周课程中的图片数据集
    :return: 数据集字典
    """
    data_info_dict = dict()
    train_set_x_orig, train_set_y_orig, test_set_x_orig, test_set_y_orig, classes = load_dataset(
    )
    print '训练集维度: %s' % str(train_set_x_orig.shape)
    print '测试集维度: %s' % str(test_set_x_orig.shape)
    # 原始数据
    data_info_dict['train_set_x_orig'] = train_set_x_orig
    data_info_dict['train_set_y_orig'] = train_set_y_orig
    data_info_dict['test_set_x_orig'] = test_set_x_orig
    data_info_dict['test_set_y_orig'] = test_set_y_orig
    # 一维化数据
    data_info_dict['train_set_x'] = train_set_x_orig.reshape(
        train_set_x_orig.shape[0], -1).T / 255.0
    data_info_dict['test_set_x'] = test_set_x_orig.reshape(
        test_set_x_orig.shape[0], -1).T / 255.0
    # 信息
    data_info_dict['classes'] = classes
    data_info_dict['n_train'] = train_set_x_orig.shape[0]
    data_info_dict['n_test'] = test_set_x_orig.shape[0]
    data_info_dict['pic_size'] = (train_set_x_orig[1:])
    return data_info_dict
예제 #2
0
파일: NN.py 프로젝트: Chiduru123/base_model
    p = np.zeros((1, m))

    # 根据参数前向传播
    probas, caches = L_model_forward(X, parameters)

    for i in range(0, probas.shape[1]):
        if probas[0, i] > 0.5:
            p[0, i] = 1
        else:
            p[0, i] = 0

    print("准确度为: " + str(float(np.sum((p == y)) / m)))
    return p


train_set_x_orig, train_set_y, test_set_x_orig, test_set_y, classes = lr_utils.load_dataset(
)

train_x_flatten = train_set_x_orig.reshape(train_set_x_orig.shape[0], -1).T
test_x_flatten = test_set_x_orig.reshape(test_set_x_orig.shape[0], -1).T

train_x = train_x_flatten / 255
train_y = train_set_y
test_x = test_x_flatten / 255
test_y = test_set_y

layers_dims = [12288, 20, 7, 5, 1]  # 5-layer model
parameters = mlp(train_x,
                 train_y,
                 layers_dims,
                 learning_rate=0.0075,
                 num_iterations=2500,
    for i in range(0, probas.shape[1]):
        if probas[0, i] > 0.5:
            p[0, i] = 1
        else:
            p[0, i] = 0

    #print results
    #print ("predictions: " + str(p))
    #print ("true labels: " + str(y))
    print("Accuracy: " + str(np.sum((p == y) / m)))
    return p


if __name__ == "__main__":
    np.random.seed(1)
    train_x_orig, train_y, test_x_orig, test_y, classes = load_dataset()
    train_x = train_x_orig.reshape(train_x_orig.shape[0], -1).T / 255.
    test_x = test_x_orig.reshape(test_x_orig.shape[0], -1).T / 255.
    # index = 10
    # plt.imshow(train_x_orig[index])
    # plt.show()
    m_train = train_x_orig.shape[0]
    m_test = test_x_orig.shape[0]
    num_px = train_x_orig.shape[1]

    n_h = 7
    n_y = 1
    layer_dims = (num_px * num_px * 3, 5, 7, 2, 1)
    # layer_dims = (num_px*num_px*3,n_h,n_y)
    # params = two_layer_model(train_x,train_y,layer_dims=layer_dims,learning_rate=0.05,num_iter=2500,print_cost=True)
    # pred_train = predict(train_x,train_y,params)