簡體   English   中英

tfp.keras.layers:如果數據格式是 'channels_first' ,我可以將網絡輸入形狀指定為 'channels_last' 嗎?

[英]tfp.keras.layers: If the data format is 'channels_first' , can I give the network input shape as 'channels_last'?

我的輸入圖像的形狀為(4,128,128,128) ,其中 data_format 為 channels_first。 在我的網絡中,我使用的是Convolution3DFlipout層,它具有默認的data_format='channels_last' 當我將 data_format 更改為:

layer = tfp.layers.Convolution3DFlipout(data_format='channels_first')(input_layer)

並提供輸入形狀為:

from tensorflow.keras.layers import Input

def model(input_shape=(4, 128, 128, 128),optimizer=Adam, initial_learning_rate=5e-4,
                      loss_function=bin_crossentropy, activation_name="sigmoid",metrics=dice_coefficient):

    inputs = Input(input_shape)
    ......

我收到以下錯誤:

TypeError: Failed to convert object of type <class 'list'> to Tensor. Contents: [None, 16, 16384, 128]. Consider casting elements to a supported type. .

  1. 當層輸出實際上應該是[None, 16, 128, 128, 128][None, 16, 16384, 128]為什么它返回[None, 16, 16384, 128] [None, 16, 128, 128, 128] 有誰知道為什么在Convolution3DFlipout()設置data_format='channels_first'會拋出這個錯誤?

  2. 如果我在數據具有形狀(4, 128, 128, 128)時將輸入形狀提供為(128,128,128,4) (這樣我就不必更改默認的 data_format (4, 128, 128, 128) ,我錯了嗎?

tfp.layers.Convolution3DFlipout()

data_format:一個字符串,channels_last(默認)或channels_first之一

.

如果您將輸入重塑為 (129,128, 128, 4),則無需在tfp.layers.Convolution3DFlipout提供 data_format 參數。

看看下面的例子,

import tensorflow as tf
import tensorflow_probability as tfp

model = tf.keras.Sequential([
    tf.keras.layers.Reshape([128, 128, 128, 4]),
    tfp.layers.Convolution3DFlipout(
        64, kernel_size=5, padding='SAME', activation=tf.nn.relu))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM