国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

腳本之家,腳本語言編程技術(shù)及教程分享平臺!
分類導(dǎo)航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服務(wù)器之家 - 腳本之家 - Python - 淺談tensorflow中Dataset圖片的批量讀取及維度的操作詳解

淺談tensorflow中Dataset圖片的批量讀取及維度的操作詳解

2020-04-08 19:08醉小義 Python

今天小編就為大家分享一篇淺談tensorflow中Dataset圖片的批量讀取及維度的操作詳解,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧

三維的讀取圖片(w, h, c):

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import tensorflow as tf
 
import glob
import os
 
 
def _parse_function(filename):
  # print(filename)
  image_string = tf.read_file(filename)
  image_decoded = tf.image.decode_image(image_string) # (375, 500, 3)
 
  image_resized = tf.image.resize_image_with_crop_or_pad(image_decoded, 200, 200)
  return image_resized
 
 
 
 
with tf.Session() as sess:
 
  print( sess.run( img ).shape  )

讀取批量圖片的讀取圖片(b, w, h, c):

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import tensorflow as tf
 
import glob
import os
 
'''
  Dataset 批量讀取圖片
'''
 
def _parse_function(filename):
  # print(filename)
  image_string = tf.read_file(filename)
  image_decoded = tf.image.decode_image(image_string) # (375, 500, 3)
 
  image_decoded = tf.expand_dims(image_decoded, axis=0)
 
  image_resized = tf.image.resize_image_with_crop_or_pad(image_decoded, 200, 200)
  return image_resized
 
 
 
img = _parse_function('../pascal/VOCdevkit/VOC2012/JPEGImages/2007_000068.jpg')
 
# image_resized = tf.image.resize_image_with_crop_or_pad( tf.truncated_normal((1,220,300,3))*10, 200, 200) 這種四維 形式是可以的
 
with tf.Session() as sess:
 
  print( sess.run( img ).shape  ) #直接初始化就可以 ,轉(zhuǎn)換成四維報(bào)錯誤,不知道為什么,若誰想明白,請留言 報(bào)錯誤
  #InvalidArgumentError (see above for traceback): Input shape axis 0 must equal 4, got shape [5]

Databae的操作:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import tensorflow as tf
 
import glob
import os
 
'''
  Dataset 批量讀取圖片:
  
    原因:
      1. 先定義圖片名的list,存放在Dataset中 from_tensor_slices()
      2. 映射函數(shù), 在函數(shù)中,對list中的圖片進(jìn)行讀取,和resize,細(xì)節(jié)
        tf.read_file(filename) 返回的是三維的,因?yàn)檫@個(gè)每次取出一張圖片,放進(jìn)隊(duì)列中的,不需要轉(zhuǎn)化為四維
        然后對圖片進(jìn)行resize, 然后每個(gè)batch進(jìn)行訪問這個(gè)函數(shù) ,所以get_next() 返回的是 [batch, w, h, c ]
      3. 進(jìn)行shuffle , batch repeat的設(shè)置
      
      4. iterator = dataset.make_one_shot_iterator() 設(shè)置迭代器
      
      5. iterator.get_next() 獲取每個(gè)batch的圖片
'''
 
def _parse_function(filename):
  # print(filename)
  image_string = tf.read_file(filename)
  image_decoded = tf.image.decode_image(image_string) #(375, 500, 3)
  '''
    Tensor` with type `uint8` with shape `[height, width, num_channels]` for
     BMP, JPEG, and PNG images and shape `[num_frames, height, width, 3]` for
     GIF images.
  '''
 
  # image_resized = tf.image.resize_images(label, [200, 200])
  ''' images 三維,四維的都可以
     images: 4-D Tensor of shape `[batch, height, width, channels]` or
      3-D Tensor of shape `[height, width, channels]`.
    size: A 1-D int32 Tensor of 2 elements: `new_height, new_width`. The
       new size for the images.
  
  '''
  image_resized = tf.image.resize_image_with_crop_or_pad(image_decoded, 200, 200)
 
  # return tf.squeeze(mage_resized,axis=0)
  return image_resized
 
filenames = glob.glob( os.path.join('../pascal/VOCdevkit/VOC2012/JPEGImages', "*." + 'jpg') )
 
 
dataset = tf.data.Dataset.from_tensor_slices((filenames))
 
dataset = dataset.map(_parse_function)
 
dataset = dataset.shuffle(10).batch(2).repeat(10)
iterator = dataset.make_one_shot_iterator()
 
img = iterator.get_next()
 
with tf.Session() as sess:
  # print( sess.run(img).shape ) #(4, 200, 200, 3)
  for _ in range (10):
    print( sess.run(img).shape )

以上這篇淺談tensorflow中Dataset圖片的批量讀取及維度的操作詳解就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持服務(wù)器之家。

原文鏈接:https://blog.csdn.net/qq_30638831/article/details/83450136

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 欧美在线观看成人 | a级免费电影 | 狠狠色狠狠色合久久伊人 | 国产精品久久久久久久久免费桃花 | 欧美喷水 | 欧美日韩一 | 久久h| 国产美女福利在线 | 欧美激情一区二区 | 国产高清精品一区二区三区 | 亚洲精品自拍 | 超碰在线免费福利 | 综合精品久久久 | 色欧美片视频在线观看 | 99久久婷婷| 在线视频一区二区三区 | 精品香蕉一区二区三区 | 日韩中文字幕在线播放 | 欧美xo影院 | 亚洲国产精品一区二区久久,亚洲午夜 | 日韩欧美在线观看一区二区 | 日韩电影免费在线观看中文字幕 | 福利视频一区二区三区 | 成人免费视频播放 | 日本一区二区免费在线播放 | 精品国产91亚洲一区二区三区www | 国产噜噜噜噜噜久久久久久久久 | 日本一区二区电影 | 欧美韩日 | 国产成人久久 | ww8888免费视频 | 亚洲综合色视频在线观看 | 午夜精品久久久久久久久久久久 | 日本不卡视频 | 日本免费三片免费观看 | 免费日韩视频 | 久久久久国产精品免费 | 亚洲国产精品一区在线 | 国产欧美综合一区二区三区 | 国产欧美精品一区二区色综合 | 国产二区三区 |