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. 写了一个Java的简单缓存模型

    缓存操作接口 /** * 缓存操作接口 * * @author xiudong * * @param <T> */ public interface Cache<T> { /* ...

  2. 姿势估计实验-Realtime_Multi-Person_Pose_Estimation-CMU

    前言: 论文及源代码网址: https://github.com/ZheC/Realtime_Multi-Person_Pose_Estimation 地址2: https://github.com/ ...

  3. Java 8 中常用的函数式接口

    函数式接口 函数描述符 Predicate<T> T->boolean Consumer<T> T->void Function<T, R> T-> ...

  4. PHP 打开已有图片进行编辑

    <?php header("content-type:image/jpeg");//表明请求页面的内容是jpeg格式的图像 即当前页面会以图片的新式展示 去掉这行就可以显示正 ...

  5. Windows7 密码修改

    一:不用输入原密码的方式修改用户的密码 1 命令行输入命令:mmc  #进入到控制台 2 点击左上角的文件,选择添加/删除管理单元 3 选择本地用户和组管理单元,添加到本地计算机,完成,确定 4 添加 ...

  6. APK重编译

    最近沉迷某游戏 尝试了一些不可描述的东西 , 记录一下研究过程 具体是哪个app不公开 ... 准备工具 APKtool && signapk && jre .net ...

  7. web前端3.0时代,“程序猿”如何“渡劫升仙”?

    世界上目前已经有超过18亿的网站.其中只有不到2亿的网站是活跃的.且每天都有几千个新网站不断被创造出来. 2017年成果显著,网络上出现了像Vue这样的新JavaScript框架:基于用户体验流程的开 ...

  8. Keepalived+LVS实现高可用负载均衡双主模式

    LVS是一种集群(Cluster)技术:采用IP负载均衡技术和基于内容请求分发技术.调度器具有很好的吞吐率,将请求均衡地转移到不同的服务器上执行,且调度器自动屏蔽掉服务器的故障,从而将一组服务器构成一 ...

  9. Java注解总结2

    注解是Java元数据,可以理解成代码的标签,正确使用能极大的简化代码的编写逻辑,在各种框架代码中使用也越来越多. 一.注解的应用场景 生成doc文档: 编译器类型格式检查: 运行时处理如注入依赖等 二 ...

  10. Dockerfile之nginx(六)

    一.Dokcerfile的基本指令   1)From 指定构建镜像的基础镜像 2)MAINTAINER 指定镜像的作者 3)RUN 使用前一条指令创建的镜像生产容器,并在容器中执行命令,执行结束后会自 ...