Loading [MathJax]/jax/output/CommonHTML/config.js
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >读入tfrecords文件时出现警告,程序一直运行不能停,print标记后发现未打印数据,如何修改?

读入tfrecords文件时出现警告,程序一直运行不能停,print标记后发现未打印数据,如何修改?

提问于 2019-02-18 10:42:41
回答 1关注 1查看 4.5K
代码语言:python
运行
AI代码解释
复制
"""这个是运行之后的警告提示:求助大神该怎么解决,我的标签内容是[1,0]或[0,1],图片数据是128*128*1,以下是我生成读取tfrecords文件的代码,以及神经网络反向传播中的代码,可能错误的地方我在其中进行了标注,求大神指出错误,多谢
2019-02-18 18:20:19.672703: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
WARNING:tensorflow:From C:/srtp/CNN/backward.py:46: start_queue_runners (from tensorflow.python.training.queue_runner_impl) is deprecated and will be removed in a future version.
Instructions for updating:
To construct input pipelines, use the `tf.data` module.
WARNING:tensorflow:`tf.train.start_queue_runners()` was called when no queue runners were defined. You can safely remove the call to this deprecated function.
WARNING:tensorflow:From C:\srtp\CNN\tfrecords_operate.py:40: string_input_producer (from tensorflow.python.training.input) is deprecated and will be removed in a future version.
Instructions for updating:
Queue-based input pipelines have been replaced by `tf.data`. Use `tf.data.Dataset.from_tensor_slices(string_tensor).shuffle(tf.shape(input_tensor, out_type=tf.int64)[0]).repeat(num_epochs)`. If `shuffle=False`, omit the `.shuffle(...)`.
WARNING:tensorflow:From C:\Python\lib\site-packages\tensorflow\python\training\input.py:276: input_producer (from tensorflow.python.training.input) is deprecated and will be removed in a future version.
Instructions for updating:
Queue-based input pipelines have been replaced by `tf.data`. Use `tf.data.Dataset.from_tensor_slices(input_tensor).shuffle(tf.shape(input_tensor, out_type=tf.int64)[0]).repeat(num_epochs)`. If `shuffle=False`, omit the `.shuffle(...)`.
WARNING:tensorflow:From C:\Python\lib\site-packages\tensorflow\python\training\input.py:188: limit_epochs (from tensorflow.python.training.input) is deprecated and will be removed in a future version.
Instructions for updating:
Queue-based input pipelines have been replaced by `tf.data`. Use `tf.data.Dataset.from_tensors(tensor).repeat(num_epochs)`.
WARNING:tensorflow:From C:\Python\lib\site-packages\tensorflow\python\training\input.py:197: QueueRunner.__init__ (from tensorflow.python.training.queue_runner_impl) is deprecated and will be removed in a future version.
Instructions for updating:
To construct input pipelines, use the `tf.data` module.
WARNING:tensorflow:From C:\Python\lib\site-packages\tensorflow\python\training\input.py:197: add_queue_runner (from tensorflow.python.training.queue_runner_impl) is deprecated and will be removed in a future version.
Instructions for updating:
To construct input pipelines, use the `tf.data` module.
WARNING:tensorflow:From C:\srtp\CNN\tfrecords_operate.py:41: TFRecordReader.__init__ (from tensorflow.python.ops.io_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Queue-based input pipelines have been replaced by `tf.data`. Use `tf.data.TFRecordDataset`.
WARNING:tensorflow:From C:\srtp\CNN\tfrecords_operate.py:63: shuffle_batch (from tensorflow.python.training.input) is deprecated and will be removed in a future version.
Instructions for updating:
Queue-based input pipelines have been replaced by `tf.data`. Use `tf.data.Dataset.shuffle(min_after_dequeue).batch(batch_size)`.
eee

Process finished with exit code -1"""
    
#tfrecords_operate.py

import tensorflow as tf
import csv
from PIL import Image

def write_tfRecord(tfRecordName,img_path,label_path,top_content):
    writer=tf.python_io.TFRecordWriter(tfRecordName)
    num_pic=0
    lab=[]
    with open(label_path) as lab_file:
        reader_label=lab_file.read()
        lab_initial = reader_label.split("\n")
        length = len(lab_initial)
        for i in range(length):
            lab_initial[i] = lab_initial[i].split(",")
    with open(img_path) as img_file:
        reader_img=csv.reader(img_file)
        for line in reader_img:
            s=top_content+line[0]
            img=Image.open(s)
            img=img.resize((128,128))
            img_raw=img.tobytes()
            j=0
            for j in range(length) :
                if lab_initial[j][0] in line[0]:
                     lab.append(int(lab_initial[j][1]))
                     break
            labb=[lab[num_pic],1-lab[num_pic]]
            print(s,labb)
            example=tf.train.Example(features=tf.train.Features(feature={'img_raw':tf.train.Feature(bytes_list=tf.train.BytesList(value=[img_raw])),'lab':tf.train.Feature(int64_list=tf.train.Int64List(value=labb))}))
            writer.write(example.SerializeToString())
            num_pic += 1
    writer.close()


def read_tfRecord(tfRecord_path):
    filename_queue=tf.train.string_input_producer([tfRecord_path])
    reader=tf.TFRecordReader()
    _,serialized_example=reader.read(filename_queue)
    features=tf.parse_single_example(serialized_example,features={ 'img_raw':tf.FixedLenFeature([],tf.string),'lab':tf.FixedLenFeature([2],tf.int64)})
    img=tf.decode_raw(features['img_raw'],tf.uint8)
 
    img=tf.cast(img,tf.float32)*(1./255)
    #img=tf.cast(img,tf.uint8)
    label=tf.cast(features['lab'],tf.float32)
    return img,label

def get_tfrecord(num,is_train):
    if is_train==True:
        tfRecord_path = 'train.tfrecords'
    else:
        tfRecord_path = 'test.tfrecords'
    img,label=read_tfRecord(tfRecord_path)
    img_batch,label_batch=tf.train.shuffle_batch([img,label],batch_size=num,num_threads=2,capacity=1000,min_after_dequeue=700,seed=None,enqueue_many=True)
    #提示说这句话有警告
    return img_batch,label_batch

def main():
    write_tfRecord('train.tfrecords','C:/srtp/MURA-v1.1/train_img.csv','C:/srtp/MURA-v1.1/train_label.csv','C:/srtp/')
    write_tfRecord('test.tfrecords','C:/srtp/MURA-v1.1/test_img.csv','C:/srtp/MURA-v1.1/test_label.csv','C:/srtp/')

if __name__ == '__main__':
    main()
    
    
#backward.py

import tensorflow as tf
import forward
import tfrecords_operate as data

BATCH_SIZE=100
LEARNING_RATE_BASE=0.005
LEARNING_RATE_DECAY=0.99
LEARNING_RATE_STEP=1
REGULARIZER=0.0001
STEPS=10000
MOVING_AVERAGE_DECAY=0.99
MODEL_SAVE_PATH="model/"
MODEL_NAME='cnn'
train_num_examples=3457

def backward():
    x=tf.placeholder(tf.float32,[BATCH_SIZE,forward.IMAGE_SIZE,forward.IMAGE_SIZE,forward.NUM_CHANNELS])
    y_=tf.placeholder(tf.float32,[None,forward.OUTPUT_NODE])
    y=forward.forward(x,True,REGULARIZER)
    global_step=tf.Variable(0,trainable=False)

    ce=tf.nn.sparse_softmax_cross_entropy_with_logits(logits=y,labels=tf.argmax(y_,1))
    cem=tf.reduce_mean(ce)
    loss=cem+tf.add_n(tf.get_collection('losses'))
    learning_rate = tf.train.exponential_decay(LEARNING_RATE_BASE, global_step, LEARNING_RATE_STEP, LEARNING_RATE_DECAY,
                                               staircase=True)
    train_step=tf.train.GradientDescentOptimizer(learning_rate).minimize(loss,global_step=global_step)

    ema=tf.train.ExponentialMovingAverage(MOVING_AVERAGE_DECAY,global_step)
    ema_op=ema.apply(tf.trainable_variables())
    with tf.control_dependencies([train_step,ema_op]):
        train_op=tf.no_op(name='train')

    saver=tf.train.Saver()

    with tf.Session() as sess:
        init_op=tf.global_variables_initializer()
        sess.run(init_op)

        ckpt=tf.train.get_checkpoint_state(MODEL_SAVE_PATH)
        if ckpt and ckpt.model_checkpoint_path:
            saver.restore(sess,ckpt.model_checkpoint_path)

        coord=tf.train.Coordinator()
        threads=tf.train.start_queue_runners(sess=sess,coord=coord)
        img_batch, label_batch = data.get_tfrecord(BATCH_SIZE, True)
        for i in range(STEPS):
            print('eee')#这个eee可以输出
            [xs,ys] = sess.run([img_batch,label_batch])
            reshaped_xs=tf.reshape(xs,(BATCH_SIZE,forward.IMAGE_SIZE,forward.IMAGE_SIZE,forward.NUM_CHANNELS))
            _,loss_value,step=sess.run([train_op,loss,global_step],feed_dict={x:reshaped_xs,y_:ys})
            print('888')#就是这个888一直输不出来
            if i%100==0:
                print('After %d training step(s),loss on training batch is %g.'%(step,loss_value))
                saver.save(sess,'model/cnn.ckpt',global_step=global_step)

        coord.request_stop()
        coord.join(threads)
def main():
    backward()

if __name__ == '__main__':
    main()

回答

成为首答用户。去 写回答
相关文章
Java 项目编译错误 Error:java: java.lang.ExceptionInInitializer
https://www.cwiki.us/display/JAVAZH/questions/57934274/answers/57934279
HoneyMoose
2020/02/26
3.9K0
Java 项目编译错误 Error:java: java.lang.ExceptionInInitializer
https://www.cwiki.us/display/JAVAZH/questions/57934274/answers/57934279
HoneyMoose
2020/03/02
7040
【Java】Java编译错误:需要class,interface或enum
显示的是sum方法需要class,重新检查了一下,发现是class的大括号没有把sum方法包括起来
全栈程序员站长
2022/06/27
2.3K0
【Java】Java编译错误:需要class,interface或enum
Java “constant string too long” 编译错误
当我们在 Java 编译器中输入的变量值超过 64 KB 的话,Java 编译器是不会让编译通过的,你将会得到一个 constant string too long” error from the compiler 错误。
HoneyMoose
2022/08/06
1.1K0
Java “constant string too long” 编译错误
Java高编译低运行错误(ConcurrentHashMap.keySet)
本地使用maven编译和运行时一切都正常,但是通过ci的方式,编译、打包、发布到部署环境,运行时抛出了一条显而易见的JDK版本的错误。
lambeta
2018/08/17
1.5K0
【错误记录】IntelliJ IDEA 编译 Java 文件报错 ( 错误: 非法字符: ‘\ufeff‘ )
出现该问题的原因是 IntelliJ IDEA 在创建文件时 , 为文件添加了 BOM 隐藏字符 , 这是 文件的 字节顺序标记 , 一般在 Windows 中的文件中添加 ;
韩曙亮
2023/03/30
1.8K0
【错误记录】IntelliJ IDEA 编译 Java 文件报错 ( 错误: 非法字符: ‘\ufeff‘ )
CGAL编译错误
用户3519280
2023/07/08
2690
cython编译错误
running build_extskipping ‘bbox.c’ Cython extension (up-to-date)skipping ‘nms.c’ Cython extension (up-to-date)building ‘cython_bbox’ extension{‘gcc’: [’-Wno-cpp’, ‘-Wno-unused-function’]}gcc -pthread -B /home/gsadhasivam/anaconda3/envs/r3det/compiler_compa
狼啸风云
2021/01/05
1.6K0
编译busybox错误汇总
提示错误: arm-linux-gcc:Command not found PATH里有/usr/oca/arm/bin,但是make的时候,就是找不到 arm-linux-gcc 原因: export PATH=$PATH:/usr/local/arm/bin是设置当前用户的PATH,而sudo执行make的时候,使用的是超级用户权限,那也就使用了超级用户的PATH(但是这个PATH里,并没有/usr/ local/arm/bin)
嵌入式与Linux那些事
2021/05/20
1.7K0
Jenkins 编译的时候提示错误 JAVA_HOME environment
https://www.ossez.com/t/jenkins-java-home-environment/761
HoneyMoose
2020/12/07
1.6K0
Jenkins 编译的时候提示错误 JAVA_HOME environment
Android So编译错误
看到这些错误一脸懵逼,size_t 不是基础类型吗,怎么会找不到。 google 一番没有任何结果,可以明确知到不是代码逻辑问题,是依赖的环境变量问题,具体的是哪个环境引起的错误,一头雾水。
艳龙
2021/12/16
1.6K0
编译 java_如何编译java[通俗易懂]
用命令32313133353236313431303231363533e58685e5aeb931333337613139提示符编译java程序的步骤:
全栈程序员站长
2022/09/05
2.4K0
编译 java_如何编译java[通俗易懂]
dubbo编译错误 原
    dubbo针对服务实现类做warp的时候, 用字符串拼接一个class,然后编译,但是如果方法出现以get开头无参的方法名,将导致dubbo报错,只需要把方法名修改一下,去掉get就好了
尚浩宇
2018/08/17
5580
Python编译错误集锦
1 IndentationError: expected an indented block
py3study
2020/01/06
1.1K0
gcc编译之常见错误
关于gcc问题解决 最近gcc编译出来的so库之类的使用总有问题,收集资料后简单整理下解决方法: 首先使用ldd 或者ldd -r XXX 查看文件所连接的so库有没有问题,目前我看到的经常是出现(undefined symbol: lua_getfield)在c中,动态库中的symbol就是函数名,所以一看到就知道是lua库没有链接导致函数找不到加上-llua即可以解决。 而c++由于允许重载,就出现同一个函数名可能对应多个实际的函数问题,于是就会有name mangling ,而且这个mangling完
渴望飞翔的猪
2022/07/17
1.5K0
java编译过程_Java编译运行过程
在上一篇文章中,我们了解了第一个Java入门程序,以及如何编译和运行第一个Java程序。本文主要了解以下编译和运行Java程序时会发生什么。此外,我们还会分析一些常见的问题。
全栈程序员站长
2022/08/12
2.1K0
java编译过程_Java编译运行过程
【错误记录】Groovy 工程编译报错 ( java.lang.NoClassDefFoundError: org/apache/tools/ant/util/ReaderInputStream )
右键点击工程根目录 , 选择 " Open Module Settings " 选项 ,
韩曙亮
2023/03/30
6650
【错误记录】Groovy 工程编译报错 ( java.lang.NoClassDefFoundError: org/apache/tools/ant/util/ReaderInputStream )
什么是编译错误,运行时错误及逻辑错误?
程序的错误主要分成三种: 编译链接错误(语法错误); 编译链接错误又分成编译错和链接错。 编译错就是普通意义上的语法错,编译器进行语法检查不通过,也就是程序违背了计算机语言的语法,例如:括号不匹配、变量名拼写错误、用保留字定义变量名等; 链接错是指程序通过了语法检查,但是无法生成可执行文件,最常见的是链接找不到lib库。初学者有时写了函数的声明,但是缺少函数的定义,此时就会出现链接错。 运行错误; 运行错是程序可以执行,但是在执行过程中发生异常,提前退出程序。最常见的是指针越界,打开文件失败
用户1148881
2018/01/16
9.6K0
ARM交叉编译OpenCV错误总结
剑影啸清寒
2018/01/02
3.2K0
ARM交叉编译OpenCV错误总结
点击加载更多

相似问题

Androidstudio ocr项目编译提示错误?

1455

unique_ptr :编译错误?

2310

Java SDK无法编译成dex文件?

1274

java错误求解?

0157

Xcode 7.3 编译错误怎么解决?

1261
相关问答用户
腾讯云TDP | TDP会员擅长3个领域
平安资管 | 架构师擅长4个领域
擅长3个领域
擅长5个领域
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档