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)的更多相关文章

  1. 吴裕雄 python深度学习与实践(13)

    import numpy as np import matplotlib.pyplot as plt x_data = np.random.randn(10) print(x_data) y_data ...

  2. 吴裕雄 python深度学习与实践(6)

    from pylab import * import pandas as pd import matplotlib.pyplot as plot import numpy as np filePath ...

  3. 吴裕雄 python深度学习与实践(18)

    # coding: utf-8 import time import numpy as np import tensorflow as tf import _pickle as pickle impo ...

  4. 吴裕雄 python深度学习与实践(17)

    import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data import time # 声明输 ...

  5. 吴裕雄 python深度学习与实践(16)

    import struct import numpy as np import matplotlib.pyplot as plt dateMat = np.ones((7,7)) kernel = n ...

  6. 吴裕雄 python深度学习与实践(15)

    import tensorflow as tf import tensorflow.examples.tutorials.mnist.input_data as input_data mnist = ...

  7. 吴裕雄 python深度学习与实践(14)

    import numpy as np import tensorflow as tf import matplotlib.pyplot as plt threshold = 1.0e-2 x1_dat ...

  8. 吴裕雄 python深度学习与实践(11)

    import numpy as np from matplotlib import pyplot as plt A = np.array([[5],[4]]) C = np.array([[4],[6 ...

  9. 吴裕雄 python深度学习与实践(10)

    import tensorflow as tf input1 = tf.constant(1) print(input1) input2 = tf.Variable(2,tf.int32) print ...

随机推荐

  1. cocos2dx开发之util类&方法——字符串替换

    /*将originStr字符串中的searchStr替换成replaceStr*/ std::string str_replace(std::string originStr,std::string ...

  2. day05 字典

    今日内容(dict) 1.基本格式 2.独有方法 3.公共 4.强制转换 1.基本格式 字典(可变类型,3.6之后是有序) 帮助用户去表示一个事物的信息(事物是有多个属性) 键值不能为集合,列表,字典 ...

  3. Ajax请求传递数组参数

    var ids = []; var rows=$("#tt").datagrid("getSelections"); for(var i=0; i<row ...

  4. ubuntu 初始安装完成后的一些设置

    处于安全考虑最好,使用普通用户登录. 首先以超级用户登入系统,然后执行以下步骤 第一步:设置普通用户 以下<user_name>代表普通用户的用户名 useradd -g users -d ...

  5. springMVC---业务处理流程图和最简单的springMvc搭建截图说明

    一.springMVC业务处理流程图: 二.如何搭建springMvc框架 1.建立web工程 2.引入jar包 3.创建web.xml文件 4.创建springMvc-servlet.xml文件 5 ...

  6. NN 激活函数 待修改

    Softmax 函数/算法 https://www.zhihu.com/question/23765351 RELU 激活函数及其他相关的函数 http://blog.csdn.net/u013146 ...

  7. 使用VS2015编译grpc_1.3.1

    环境: win7_x64,VS2015 开始: 一.安装工具 1. 安装cmake 2. 安装ActivePerl 3. 安装golang 4. 安装nasm 验证安装是否安装成功: cmake -v ...

  8. Dynamics 365 CRM 添加自定义按钮

    在添加自定义按钮之前,我们需要下载这个工具 RibbonWorkbench, 它是专门针对自定义命令栏和Ribbon区域. 下载之后是一个zip压缩包. 怎样安装RibbonWorkbench: Se ...

  9. JavaBasic_正则表达式

    就是符合一定规则的字符串 规则字符在java.util.regex.Pattern类中 字符转义\. 匹配.字符\* 匹配*字符\\ 匹配\字符\n 新行(换行)符 ('\u000A') \r 回车符 ...

  10. note 3 变量与简单I/O

    变量(Variable) 用于引用(绑定对象的标识符) 语法 变量名=对象(数值.表达式等) 增量赋值运算符 count = count + 1 简写 count += 1 标识符(Identifie ...