吴裕雄 python深度学习与实践(12)
import tensorflow as tf q = tf.FIFOQueue(,"float32")
counter = tf.Variable(0.0)
add_op = tf.assign_add(counter, tf.constant(1.0))
enqueueData_op = q.enqueue(counter) sess = tf.Session()
qr = tf.train.QueueRunner(q, enqueue_ops=[add_op, enqueueData_op] * )
sess.run(tf.initialize_all_variables())
enqueue_threads = qr.create_threads(sess, start=True) coord = tf.train.Coordinator()
enqueue_threads = qr.create_threads(sess, coord = coord,start=True) for i in range(, ):
print(sess.run(q.dequeue()))
coord.request_stop()
coord.join(enqueue_threads)
import os path = 'F:\\lj\\aa\\VOCdevkit\\VOC2012\\JPEGImages\\'
filenames=os.listdir(path)
strText = "" with open("E:\\train_list.csv", "w") as fid:
for a in range(len(filenames)):
strText = path+filenames[a] + "," + filenames[a].split('_')[] + "\n"
fid.write(strText)
fid.close()
import cv2
import tensorflow as tf image_add_list = []
image_label_list = []
with open("E:\\train_list.csv") as fid:
for image in fid.readlines():
image_add_list.append(image.strip().split(",")[0])
image_label_list.append(image.strip().split(",")[1]) img=tf.image.convert_image_dtype(tf.image.decode_jpeg(tf.read_file('F:\\lj\\aa\\VOCdevkit\\VOC2012\\JPEGImages\\2007_000250.jpg'),channels=1),dtype=tf.float32)
print(img)
import cv2
import tensorflow as tf image_add_list = []
image_label_list = []
with open("E:\\train_list.csv") as fid:
for image in fid.readlines():
image_add_list.append(image.strip().split(",")[0])
image_label_list.append(image.strip().split(",")[1]) def get_image(image_path):
return tf.image.convert_image_dtype(tf.image.decode_jpeg(tf.read_file(image_path), channels=1),dtype=tf.uint8) img = tf.image.convert_image_dtype(tf.image.decode_jpeg(tf.read_file('F:\\lj\\aa\\VOCdevkit\\VOC2012\\JPEGImages\\2007_000250.jpg'), channels=1),dtype=tf.float32) with tf.Session() as sess:
cv2Img = sess.run(img)
img2 = cv2.resize(cv2Img, (200,200))
cv2.imshow('image', img2)
cv2.waitKey(0)
import numpy as np
import tensorflow as tf a_data = 0.834
b_data = [17]
c_data = np.array([[0,1,2],[3,4,5]])
c = c_data.astype(np.uint8)
c_raw = c.tostring() #转化成字符串 example = tf.train.Example(
features=tf.train.Features(
feature={
'a': tf.train.Feature(float_list=tf.train.FloatList(value=[a_data])),
'b': tf.train.Feature(int64_list=tf.train.Int64List(value=b_data)),
'c': tf.train.Feature(bytes_list=tf.train.BytesList(value=[c_raw]))
}
)
)
import numpy as np
import tensorflow as tf writer = tf.python_io.TFRecordWriter("E:\\trainArray.tfrecords")
for _ in range(100):
randomArray = np.random.random((1,3))
array_raw = randomArray.tobytes()
example = tf.train.Example(features=tf.train.Features(feature={
"label": tf.train.Feature(int64_list=tf.train.Int64List(value=[0])),
'img_raw': tf.train.Feature(bytes_list=tf.train.BytesList(value=[array_raw]))
}))
writer.write(example.SerializeToString())
writer.close()
import os
import tensorflow as tf
from PIL import Image path = "E:\\tupian"
filenames=os.listdir(path)
writer = tf.python_io.TFRecordWriter("E:\\train.tfrecords") for name in filenames:
class_path = path + os.sep + name
for img_name in os.listdir(class_path):
img_path = class_path+os.sep+img_name
img = Image.open(img_path)
img = img.resize((500,500))
img_raw = img.tobytes()
example = tf.train.Example(features=tf.train.Features(feature={
"label": tf.train.Feature(int64_list=tf.train.Int64List(value=[int(name.split("_")[0])])),
'image': tf.train.Feature(bytes_list=tf.train.BytesList(value=[img_raw]))
}))
writer.write(example.SerializeToString())
import cv2
import tensorflow as tf filename = "E:\\train.tfrecords"
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, [300, 300,3]) img = tf.cast(img, tf.float32) * (1. / 128) - 0.5
label = tf.cast(features['label'], tf.int32)
import cv2
import tensorflow as tf filename = "E:\\train.tfrecords"
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, [300, 300,3]) sess = tf.Session()
init = tf.initialize_all_variables() sess.run(init)
threads = tf.train.start_queue_runners(sess=sess) img = tf.cast(img, tf.float32) * (1. / 128) - 0.5
label = tf.cast(features['label'], tf.int32) print(img)
# imgcv2 = sess.run(img)
# cv2.imshow("cool",imgcv2)
# cv2.waitKey(0)
import cv2
import tensorflow as tf filename = "E:\\train.tfrecords" 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, [300, 300,3]) img = tf.cast(img, tf.float32) * (1. / 128) - 0.5
label = tf.cast(features['label'], tf.int32)
return img,label img,label = read_and_decode(filename) img_batch,label_batch = tf.train.shuffle_batch([img,label],batch_size=1,capacity=10,min_after_dequeue=1) init = tf.initialize_all_variables()
sess = tf.Session()
sess.run(init)
threads = tf.train.start_queue_runners(sess=sess) for _ in range(10):
val = sess.run(img_batch)
label = sess.run(label_batch)
val.resize((300,300,3))
cv2.imshow("cool",val)
cv2.waitKey()
print(label)
吴裕雄 python深度学习与实践(12)的更多相关文章
- 吴裕雄 python深度学习与实践(13)
import numpy as np import matplotlib.pyplot as plt x_data = np.random.randn(10) print(x_data) y_data ...
- 吴裕雄 python深度学习与实践(6)
from pylab import * import pandas as pd import matplotlib.pyplot as plot import numpy as np filePath ...
- 吴裕雄 python深度学习与实践(18)
# coding: utf-8 import time import numpy as np import tensorflow as tf import _pickle as pickle impo ...
- 吴裕雄 python深度学习与实践(17)
import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data import time # 声明输 ...
- 吴裕雄 python深度学习与实践(16)
import struct import numpy as np import matplotlib.pyplot as plt dateMat = np.ones((7,7)) kernel = n ...
- 吴裕雄 python深度学习与实践(15)
import tensorflow as tf import tensorflow.examples.tutorials.mnist.input_data as input_data mnist = ...
- 吴裕雄 python深度学习与实践(14)
import numpy as np import tensorflow as tf import matplotlib.pyplot as plt threshold = 1.0e-2 x1_dat ...
- 吴裕雄 python深度学习与实践(11)
import numpy as np from matplotlib import pyplot as plt A = np.array([[5],[4]]) C = np.array([[4],[6 ...
- 吴裕雄 python深度学习与实践(10)
import tensorflow as tf input1 = tf.constant(1) print(input1) input2 = tf.Variable(2,tf.int32) print ...
随机推荐
- 【转载】 强化学习(九)Deep Q-Learning进阶之Nature DQN
原文地址: https://www.cnblogs.com/pinard/p/9756075.html ------------------------------------------------ ...
- cocos2dx解决中文乱码方法
使用plist文件,优点方便做多国语言支持~也不用去做编码转换 1.Resource目录下新建text.plist文件,内容格式如下 <?xml version="1.0" ...
- s21day06 python笔记
s21day06 python笔记 一.昨日内容回顾及补充 回顾 补充 列表独有功能 reverse:反转 v = [1,2,3,4,5] v.reverse() #[5,4,3,2,1] sort: ...
- Python全栈之路----常用模块----random模块
程序中有很多地方需要用到随机字符,比如登陆网站的随机验证码,通过random模块可以很容易生成随机字符串. >>> import random >>> random ...
- tree-lstm初探
https://zhuanlan.zhihu.com/p/35252733 可以先看看上面知乎文章里面的例子 Socher 等人于2012和2013年分别提出了两种区分词或短语类型的模型,即SU-RN ...
- jquery中filter的用法
一.filter的参数类型可分为两种 1.传递选择器 $('a').filter('.external') 2.传递过滤函数 $('a').filter(function(index) { ...
- Linux 分支那么多,这里可以帮你缩小选择范围
Linux 分支那么多,这里可以帮你缩小选择范围 https://wiki.installgentoo.com/wiki/Babbies_First_Linux https://wiki.instal ...
- 使用openresty && minio && thumbor 构建稳定高效的图片服务器
备注: minio 是一个开源的s3 协议兼容的分布式存储,openresty nginx+lua 高性能可扩展的nginx 衍生版,thumbor 基于python 的图片处理服务器,支持图片的裁剪 ...
- Amundsen — Lyft’s data discovery & metadata engine
转自:https://eng.lyft.com/amundsen-lyfts-data-discovery-metadata-engine-62d27254fbb9 In order to incre ...
- 项目期复习:JS操作符,弹窗与调试,凝视,数据类型转换
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/huangyibin628/article/details/26364901 1.JS操作符 ① 除法 ...