• input_fn如何读取数据


    1,简单数pandas

    import pandas

    train_df = pandas.read_csv(train_file, header = None, names = census_dataset._CSV_COLUMNS)
    test_df = pandas.read_csv(test_file, header = None, names = census_dataset._CSV_COLUMNS)

    train_df.head()

    2,从pandas的data frame中读取数据

    ds = easy_input_function(train_df, label_key='income_bracket', num_epochs=5, shuffle=True, batch_size=10)

    for feature_batch, label_batch in ds.take(1):
    print('Some feature keys:', list(feature_batch.keys())[:5])
    print()
    print('A batch of Ages :', feature_batch['age'])
    print()
    print('A batch of Labels:', label_batch )

    3,利用tf_data直接从文件系统读取数据

    ds = census_dataset.input_fn(train_file, num_epochs=5, shuffle=True, batch_size=10)

    for feature_batch, label_batch in ds.take(1):
    print('Feature keys:', list(feature_batch.keys())[:5])
    print()
    print('Age batch :', feature_batch['age'])
    print()
    print('Label batch :', label_batch )

  • 相关阅读:
    shell 编写简单的整数计算器
    信号控制
    MySQL-索引及优化整理
    Java面试-Java容器有哪些
    C语言宏定义
    值类型与引用类型的区别
    C++虚函数简介
    DNS-域名解析
    扇区,簇,块区分
    Java合并两个数组为一个新数组
  • 原文地址:https://www.cnblogs.com/augustone/p/10505931.html
Copyright © 2020-2023  润新知