zoukankan      html  css  js  c++  java
  • tfrecords读入

    #!/usr/bin/env python

    import tensorflow as tf
    import numpy as np
    def read_and_decode(filename): # 读入dog_train.tfrecords
    filename_queue = tf.train.string_input_producer([filename])#生成一个queue队列
    reader = tf.TFRecordReader()
    _, serialized_example = reader.read(filename_queue)#返回文件名和文件
    features = tf.parse_single_example(serialized_example,
    features={
    'label': tf.FixedLenFeature([], tf.int64),
    'img_raw' : tf.FixedLenFeature([], tf.string),
    })#将image数据和label取出来
    img = tf.decode_raw(features['img_raw'], tf.uint8)
    img = tf.reshape(img, [4, 4, 1])#reshape为128*128的3通道图片
    #img = tf.cast(img, tf.float32) * (1. / 255) - 0.5 #在流中抛出img张量
    label = tf.cast(features['label'], tf.int32) #在流中抛出label张量
    return img, label
    read_and_decode('train.tfrecords')
  • 相关阅读:
    day 1 认识js
    day2,request对象
    day3
    day 14 函数的嵌套,作用域
    命名空间(名称空间)
    day 13 函数
    day 11(2) 集合
    day 11 字典拆包
    字典
    两周英语函数(记)
  • 原文地址:https://www.cnblogs.com/rongye/p/10028930.html
Copyright © 2011-2022 走看看