日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

tf.expand_dims()

發布時間:2023/11/28 生活经验 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 tf.expand_dims() 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
tf.expand_dims()

轉載:https://blog.csdn.net/jasonzzj/article/details/60811035

TensorFlow中,想要維度增加一維,可以使用tf.expand_dims(input, dim, name=None)函數。當然,我們常用tf.reshape(input, shape=[])也可以達到相同效果,但是有些時候在構建圖的過程中,placeholder沒有被feed具體的值,這時就會包下面的錯誤:TypeError: Expected binary or unicode string, got 1?
在這種情況下,我們就可以考慮使用expand_dims來將維度加1。比如我自己代碼中遇到的情況,在對圖像維度降到二維做特定操作后,要還原成四維[batch, height, width, channels],前后各增加一維。如果用reshape,則因為上述原因報錯

one_img2 = tf.reshape(one_img, shape=[1, one_img.get_shape()[0].value, one_img.get_shape()[1].value, 1])

用下面的方法可以實現:

one_img = tf.expand_dims(one_img, 0)
one_img = tf.expand_dims(one_img, -1) #-1表示最后一維

在最后,給出官方的例子和說明

# 't' is a tensor of shape [2]
shape(expand_dims(t, 0)) ==> [1, 2]
shape(expand_dims(t, 1)) ==> [2, 1]
shape(expand_dims(t, -1)) ==> [2, 1]# 't2' is a tensor of shape [2, 3, 5]
shape(expand_dims(t2, 0)) ==> [1, 2, 3, 5]
shape(expand_dims(t2, 2)) ==> [2, 3, 1, 5]
shape(expand_dims(t2, 3)) ==> [2, 3, 5, 1]

Args:?
input: A Tensor.?
dim: A Tensor. Must be one of the following types: int32, int64. 0-D (scalar). Specifies the dimension index at which to expand the shape of input.?
name: A name for the operation (optional).

Returns:?
A Tensor. Has the same type as input. Contains the same data as input, but its shape has an additional dimension of size 1 added.

?

年歲有加并非垂老 理想丟棄方墮暮年

總結

以上是生活随笔為你收集整理的tf.expand_dims()的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。