zoukankan      html  css  js  c++  java
  • 学习七

    学会读取图片并转化为张量

    import tensorflow as tf
    import os
    
    
    #读取狗图片并转换成张量
    def  picread(filelist):
        file_queue=tf.train.string_input_producer(filelist)
        #构造阅读器读取图片内容,默认读取一张图片
        reader=tf.WholeFileReader()
        key,value=reader.read(file_queue)
        print(value)
        #解码
        image=tf.image.decode_jpeg(value)
        print(image)
        #处理图片的大小统一
        image_resize=tf.image.resize_images(image,[200,200])
        print(image_resize)
        #注意一定要把样本的形状固定,批处理要求所有数据形状必须定义
        image_resize.set_shape([200,200,3])
        #进行批处理
        image_batch=tf.train.batch([image_resize],batch_size=10,num_threads=1,capacity=10)
        print(image_batch)
        return image_batch
    
    
    
    
    if __name__=="__main__":
        file_name=os.listdir("./data/dog/")
        file_list=[os.path.join("./data/dog/",file)for file in file_name]
        image_batch=picread(file_list)
        with tf.Session() as sess:
            coord=tf.train.Coordinator()
            threads=tf.train.start_queue_runners(sess,coord=coord)
            print(sess.run(image_batch))
            coord.request_stop()
            coord.join(threads)
  • 相关阅读:
    根据用户行为发送客服消息
    tp5链接访问
    统计每天分享次数总和
    csv中文乱码
    Jupyter Notebook命令
    Laplace(拉普拉斯)算子
    Sobel算子
    Opencv图像连通域
    Opencv常用函数讲解
    12306 Pytho抢票代码
  • 原文地址:https://www.cnblogs.com/zhang12345/p/13073034.html
Copyright © 2011-2022 走看看