美文网首页
2018-08-14 tensorflow-mnist

2018-08-14 tensorflow-mnist

作者: 镜中无我 | 来源:发表于2019-02-18 17:16 被阅读0次

    mnist.py provides a sort of methods to process file IO

    main class

    class DataSeta(object):

    main method

    read_data_sets(train_dir, fake_data, one_hot, dtype=dtypes.float32,...,source_url)
    if fake_data:
    if not source_url:
       source_url=DEFAULT_SOURCE_URL
    local_file=base.maybe_download(TRAIN_IMAGES,train_dir, source_url+TRAIN_IMAGES)
    #base.maybe_download() return a filepath in which you can always find the target file
    with gfile.Open(local_file,'rb') as f:
           train_images=extract_images(f)
    local_file=base.maybe_download(TRAIN_LABEALS,train_dir, source_url+LABELS)
    #base.maybe_download() return a filepath in which you can always find the target file
    with gfile.Open(local_file,'rb') as f:
           train_images=extract_labels(f)
    local_file=base.maybe_download(TEST_IMAGES,train_dir, source_url+TEST_IMAGES)
    #base.maybe_download() return a filepath in which you can always find the target file
    with gfile.Open(local_file,'rb') as f:
           test_images=extract_images(f)
    local_file=base.maybe_download(TEST_LABELS,train_dir, source_url+TEST_LABELS)
    #base.maybe_download() return a filepath in which you can always find the target file
    with gfile.Open(local_file,'rb') as f:
           test_labels=extract_labels(f)
    return base.Datasets(train=train, validation=validation,test=test)
    # Datasets is a collections.nametuple('Datasets',['train','validation','test'])
    
    base.maybe_download(filename,work_directory,source_url)
    if not gfile.Exists(work_directory):
       gfile.MakeDirs(work_directory)
    filepath=os.path.join(work_directory,filename)
    if not gfile.Exists(filepath):
       temp_file_name,_=urlretrieve_with_retry(source_url)
    #download the file from remote server
       gfile.Copy(temp_file_name,filepath)
        with gfile.GFile(filepath) as f:
        size=f.size()
    return filepath

    相关文章

      网友评论

          本文标题:2018-08-14 tensorflow-mnist

          本文链接:https://www.haomeiwen.com/subject/lzdvbftx.html