当前位置: 首页 > news >正文

营销网站用户体验有哪些商标在线设计logo图案

营销网站用户体验有哪些,商标在线设计logo图案,可以做热图的在线网站,最好的网站建设报价本文面对三种常常遇到的情况#xff0c;总结三种读取数据的方式#xff0c;分别用于处理单张图片、大量图片#xff0c;和TFRecorder读取方式。并且还补充了功能相近的tf函数。1、处理单张图片我们训练完模型之后#xff0c;常常要用图片测试#xff0c;有的时候#xff…本文面对三种常常遇到的情况总结三种读取数据的方式分别用于处理单张图片、大量图片和TFRecorder读取方式。并且还补充了功能相近的tf函数。1、处理单张图片我们训练完模型之后常常要用图片测试有的时候我们并不需要对很多图像做测试可能就是几张甚至一张。这种情况下没有必要用队列机制。import tensorflow as tfimport matplotlib.pyplot as pltdef read_image(file_name):img tf.read_file(filenamefile_name) # 默认读取格式为uint8print(img 的类型是,type(img));img tf.image.decode_jpeg(img,channels0) # channels 为1得到的是灰度图为0则按照图片格式来读return imgdef main( ):with tf.device(/cpu:0):# img_path是文件所在地址包括文件名称地址用相对地址或者绝对地址都行img_path./1.jpgimgread_image(img_path)with tf.Session() as sess:image_numpysess.run(img)print(image_numpy)print(image_numpy.dtype)print(image_numpy.shape)plt.imshow(image_numpy)plt.show()if __name____main__:main()输出结果为img 的类型是 [[[196 219 209][196 219 209][196 219 209]...[[ 71 106  42][ 59  89  39][ 34  63  19]...[ 21  52  46][ 15  45  43][ 22  50  53]]]uint8(675, 1200, 3)和tf.read_file用法相似的函数还有tf.gfile.FastGFile  tf.gfile.GFile只是要指定读取方式是r 还是rb 。2、需要读取大量图像用于训练这种情况就需要使用Tensorflow队列机制。首先是获得每张图片的路径把他们都放进一个list里面然后用string_input_producer创建队列再用tf.WholeFileReader读取。具体请看下例def get_image_batch(data_file,batch_size):data_names[os.path.join(data_file,k) for k in os.listdir(data_file)]#这个num_epochs函数在整个Graph是local Variable所以在sess.run全局变量的时候也要加上局部变量。filenames_queuetf.train.string_input_producer(data_names,num_epochs50,shuffleTrue,capacity512)readertf.WholeFileReader()_,img_bytesreader.read(filenames_queue)imagetf.image.decode_png(img_bytes,channels1) #读取的是什么格式就decode什么格式#解码成单通道的并且获得的结果的shape是[?, ?,1]也就是Graph不知道图像的大小需要set_shapeimage.set_shape([180,180,1]) #set到原本已知图像的大小。或者直接通过tf.image.resize_imagestf.reshape()imagetf.image.convert_image_dtype(image,tf.float32)#预处理 下面的一句代码可以换成自己想使用的预处理方式#imagetf.divide(image,255.0)return tf.train.batch([image],batch_size)这里的date_file是指文件夹所在的路径不包括文件名。第一句是遍历指定目录下的文件名称存放到一个list中。当然这个做法有很多种方法比如glob.glob或者tf.train.match_filename_once全部代码如下import tensorflow as tfimport osdef read_image(data_file,batch_size):data_names[os.path.join(data_file,k) for k in os.listdir(data_file)]filenames_queuetf.train.string_input_producer(data_names,num_epochs5,shuffleTrue,capacity30)readertf.WholeFileReader()_,img_bytesreader.read(filenames_queue)imagetf.image.decode_jpeg(img_bytes,channels1)imagetf.image.resize_images(image,(180,180))imagetf.image.convert_image_dtype(image,tf.float32)return tf.train.batch([image],batch_size)def main( ):img_pathrF:\dataSet\WIDER\WIDER_train\images\6--Funeral #本地的一个数据集目录有足够的图像imgread_image(img_path,batch_size10)imageimg[0] #取出每个batch的第一个数据print(image)init[tf.global_variables_initializer(),tf.local_variables_initializer()]with tf.Session() as sess:sess.run(init)coord tf.train.Coordinator()threads tf.train.start_queue_runners(sesssess,coordcoord)try:while not coord.should_stop():print(image.shape)except tf.errors.OutOfRangeError:print(read done)finally:coord.request_stop()coord.join(threads)if __name____main__:main()输出如下(180, 180, 1)(180, 180, 1)(180, 180, 1)(180, 180, 1)(180, 180, 1)这段代码可以说写的很是规整了。注意到init里面有对local变量的初始化并且因为用到了队列当然要告诉电脑什么时候队列开始, tf.train.Coordinator 和 tf.train.start_queue_runners 就是两个管理队列的类用法如程序所示。与 tf.train.string_input_producer相似的函数是 tf.train.slice_input_producer。 tf.train.slice_input_producer和tf.train.string_input_producer的第一个参数形式不一样。等有时间再做一个二者比较的博客3、对TFRecorder解码获得图像数据其实这块和上一种方式差不多的更重要的是怎么生成TFRecorder文件这一部分我会补充到另一篇博客上。仍然使用 tf.train.string_input_producer。import tensorflow as tfimport matplotlib.pyplot as pltimport osimport cv2import numpy as npimport globdef read_image(data_file,batch_size):files_pathglob.glob(data_file)queuetf.train.string_input_producer(files_path,num_epochsNone)reader tf.TFRecordReader()print(queue)_, serialized_example reader.read(queue)features tf.parse_single_example(serialized_example,features{image_raw: tf.FixedLenFeature([], tf.string),label_raw: tf.FixedLenFeature([], tf.string),})image tf.decode_raw(features[image_raw], tf.uint8)image tf.cast(image, tf.float32)image.set_shape((12*12*3))label tf.decode_raw(features[label_raw], tf.float32)label.set_shape((2))# 预处理部分省略大家可以自己根据需要添加return tf.train.batch([image,label],batch_sizebatch_size,num_threads4,capacity5*batch_size)def main( ):img_pathrF:\python\MTCNN_by_myself\prepare_data\pnet*.tfrecords #本地的几个tf文件img,labelread_image(img_path,batch_size10)imageimg[0]init[tf.global_variables_initializer(),tf.local_variables_initializer()]with tf.Session() as sess:sess.run(init)coord tf.train.Coordinator()threads tf.train.start_queue_runners(sesssess,coordcoord)try:while not coord.should_stop():print(image.shape)except tf.errors.OutOfRangeError:print(read done)finally:coord.request_stop()coord.join(threads)if __name____main__:main()在read_image函数中先使用glob函数获得了存放tfrecord文件的列表然后根据TFRecord文件是如何存的就如何parse再set_shape这里有必要提醒下parse的方式。我们看到这里用的是tf.decode_raw 因为做TFRecord是将图像数据string化了数据是串行的丢失了空间结果。从features中取出image和label的数据这时就要用 tf.decode_raw  解码得到的结果当然也是串行的了所以set_shape 成一个串行的再reshape。这种方式是取决于你的编码TFRecord方式的。再举一种例子readertf.TFRecordReader()_,serialized_examplereader.read(file_name_queue)features tf.parse_single_example(serialized_example, features{data: tf.FixedLenFeature([256,256], tf.float32), ###label: tf.FixedLenFeature([], tf.int64),id: tf.FixedLenFeature([], tf.int64)})img features[data]label features[label]id features[id]这个时候就不需要任何解码了。因为做TFRecord的方式就是直接把图像数据append进去了。参考链接到此这篇关于浅谈TensorFlow中读取图像数据的三种方式的文章就介绍到这了,更多相关TensorFlow 读取图像数据内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家
http://wiki.neutronadmin.com/news/263772/

相关文章:

  • 佳木斯 两学一做 网站网络营销发展方案策划书
  • 梧州网站建设贝尔利wordpress更改网页标题
  • 绍兴企业免费建站关键词挖掘工具站
  • 天津哪家公司做企业网站做爰网站贴吧
  • 佛山免费建站找哪家wordpress小说插件
  • 照片书那个网站做的好农村自建房室内装修设计效果图
  • 网站建设回访wordpress手机版怎么做
  • 做网站买那种服务器天河手机建网站
  • 网站开发的售后 维保dw网页制作成品代码加图片
  • 如何查询网站点击量关键词优化网站排名
  • 如何用源代码做网站网站建设报价包括哪些
  • 如何分析一个网站的用户网站风格抄袭
  • 怎样做网站首页图片变换怎么自学室内设计与装修
  • 网站开发php jspwordpress页面制作
  • 广州天河区网站建设公司制作图片二维码
  • 东莞营销型网站建站wordpress如何修改首页文件模板
  • 建设公司网站需要准备什么高端网站设计制作的
  • 自助建设视频网站单页网站模板安装
  • 泌阳专业网站建设建设手机网站例
  • 广东高端网站设计公司wordpress资源网模板
  • 专业的网站建设公司电话余姚什么网站做装修比较好
  • 西乡网站开发做图专业软件下载网站有哪些
  • 个人网站 免备案上海seo公司
  • 阳江企业网站国家开发银行生源地助学贷款网站
  • 网站建设湖南岚鸿建设旅游电子商务网站的建设
  • 专业摄影网站推荐做网站需要代码吗
  • 网站怎么做七牛云加速软件大全免费下载
  • 做网站接广告赚钱吗湖南企业网站建设制作
  • 如今流行的网站建设网站建设的完整流程包括
  • 利用已有网站 制作南京高端定制网站建设