深度学习-读取图片代码(tensorflow1)

# 导入模块
import os
import tensorflow as tf
import time
import numpy as np
# 获取文件完整路径
start=time.time()
filename = os.listdir(r"F:/data_dog/dog")
print(filename)
filelist = [os.path.join(r"F:/data_dog/dog/", file) for file in filename]
print(filelist)
# 构造文件名队列
filequeue = tf.train.string_input_producer(filelist)
print("filequeue:\n",filequeue.size())
# 构造文件读取器
reader = tf.WholeFileReader()
# 读取数据
key, value = reader.read(filequeue)
print(key)
print(value)
# 对value进行解码
image = tf.image.decode_jpeg(value)
print("image:\n",image.shape)
# 统一形状
image_reshape = tf.image.resize_images(image, [200, 200])
print("image_reshape:\n", image_reshape)
image_reshape.set_shape([200,200,3])
print("image_reshape:\n",image_reshape)
# 修改数据类型dtype
image_reshape_newdata = tf.cast(image_reshape, tf.float32)
print("image_reshape_newdata:\n",image_reshape_newdata)
# 批处理
image_batch=tf.train.batch([image_reshape_newdata],batch_size=50,capacity=100)
print("image_batch:\n",image_batch)
# 开启会话
with tf.Session() as sess:
    # 创建线程协调员
    coord = tf.train.Coordinator()
    # 创建队列的线程
    threads = tf.train.start_queue_runners(sess, coord)
    image_value = sess.run(image)
    print("image_value:\n", image_value)
    image_reshape_value = sess.run(image_reshape)
    print("image_reshape_value:\n", image_reshape_value)
    image_batch_value = sess.run(image_batch)
    print("image_batch_value:\n", image_batch_value)
    coord.request_stop()
    coord.join(threads)
end=time.time()
print('时长:\n',end-start)

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值