XJTU_Ironboy 2017-09-04 14:30 采纳率: 0%
浏览 4899

怎么在TensorFlow上导入ImageNet数据进行试验?

请问一下,将数据集转为tfrecord格式之后,自己load数据的时候经常跑到一半报错

tensorflow.python.framework.errors_impl.OutOfRangeError: RandomShuffleQueue '_1_shuffle_batch/random_shuffle_queue' is closed and has insufficient elements (requested 1, current size 0)
     [[Node: shuffle_batch = QueueDequeueUpToV2[component_types=[DT_UINT8, DT_INT32], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/device:CPU:0"](shuffle_batch/random_shuffle_queue, shuffle_batch/n)]]

怎么回事,我这部分的代码大致是这样的:

import os
import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt 
import tensorflow.contrib.slim as slim
from PIL import Image
tfrecord_paths = "./ImageNet_validate.tfrecord"
def read_and_decode(filename):
    #根据文件名生成一个队列
    filename_queue = tf.train.string_input_producer([filename])

    reader = tf.TFRecordReader()
    _, serialized_example = reader.read(filename_queue)   #返回文件名和文件
    features = tf.parse_single_example(serialized_example,
                                       features={
                                           'label': tf.FixedLenFeature([], tf.int64),
                                           'image' : tf.FixedLenFeature([], tf.string),
                                       })

    img = tf.decode_raw(features['image'], tf.uint8)
    img = tf.reshape(img,[1,433200])
    # img = tf.reshape(img, [380, 380, 3])
    # img = tf.cast(img, tf.float32) * (1. / 255) - 0.5
    label = tf.cast(features['label'], tf.int32)

    return img, label

img, label = read_and_decode(tfrecord_paths)

img_batch, label_batch = tf.train.shuffle_batch([img, label],
                                                batch_size=1, capacity=1000,
                                                num_threads = 512,
                                                allow_smaller_final_batch=True,
                                                min_after_dequeue=1)

global_init = tf.global_variables_initializer()
local_init = tf.local_variables_initializer()

with tf.Session() as sess:
    sess.run(global_init)
    sess.run(local_init)
    coord=tf.train.Coordinator()
    threads= tf.train.start_queue_runners(coord=coord)
    for i in range(1000):
        print(i)
        print("image:",img_batch.get_shape().as_list())
        print("label:",label_batch.get_shape().as_list())
        val, l= sess.run([img_batch,label_batch])
        print(val.shape, l)
  • 写回答

2条回答

  • xiaoyaoyao17 2018-08-06 06:48
    关注

    需要生成 TFRcords 才可以用 TensorFlow 读取

    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)