首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >读入tfrecords文件时出现警告,程序一直运行不能停,print标记后发现未打印数据,如何修改?

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

提问于 2019-02-18 18:42:41
回答 1关注 1查看 4.4K
代码语言:python
复制
"""这个是运行之后的警告提示:求助大神该怎么解决,我的标签内容是[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()

回答

和开发者交流更多问题细节吧,去 写回答
相关文章

相似问题

相关问答用户
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档