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. 3.2 unittest执行顺序

    3.2 unittest执行顺序 前言很多初学者在使用unittest框架时候,不清楚用例的执行顺序到底是怎样的.对测试类里面的类和方法分不清楚,不知道什么时候执行,什么时候不执行.本篇通过最简单案例 ...

  2. 全栈爬取-Scrapy框架(CrawlSpider)

    引入 提问:如果想要通过爬虫程序去爬取”糗百“全站数据新闻数据的话,有几种实现方法? 方法一:基于Scrapy框架中的Spider的递归爬取进行实现(Request模块递归回调parse方法). 方法 ...

  3. 位运算 - 最短Hamilton路径

    给定一张 n 个点的带权无向图,点从 0~n-1 标号,求起点 0 到终点 n-1 的最短Hamilton路径. Hamilton路径的定义是从 0 到 n-1 不重不漏地经过每个点恰好一次. 输入格 ...

  4. strstr函数的运用

    strstr函数用于搜索一个字符串在另一个字符串中的第一次出现,该函数返回字符串的其余部分(从匹配点).如果未找到所搜索的字符串,则返回 false.

  5. XML二

    XML的语法要求: 1,XML文档必须有一个顶层元素,即文档元素,所有其他元素必须嵌入在文档元素中. 2,元素嵌套要正确,即如果一个元素在另一个元素中开始,那么必须在同一个元素中结束. 3,每个元素必 ...

  6. CodeForces - 455D

    Serega loves fun. However, everyone has fun in the unique manner. Serega has fun by solving query pr ...

  7. Unreal Engine 4 C++ UCLASS构造函数易出错分析

    Unreal Engine 4 C UCLASS构造函数易出错分析 GENERATED_BODY GENERATED_UCLASS_BODY 在Unreal Engine 4的任意类中通常会见到两个宏 ...

  8. win7共享打印机如何设置,xp系统如何连接共享打印机。

    一.xp如何连接win7共享打印机——连接win7共享打印机出现“禁用当前的账户”怎么办   保证xp和win7在同一局域网内.然后在xp电脑中打开[运行],输入win7电脑的ip地址.比如,我的办公 ...

  9. 聊聊Java反射

    反射是Java最重要的特性.通过Java反射可以在运行时知道一个类的所有成员和方法,知道一个对象的类类型.成员和方法的所有信息,进而调用对象的方法或生成对象的代理或包装类. Java是面向对象语言,除 ...

  10. maven 项目使用本地jar

    <dependency> <groupId>com.yeepay.g3</groupId> <artifactId>yop</artifactId ...