Dealing with shape [None, None, None] in tensorflow

I am working with a simple TensorFlow model given by

    model = models.Sequential()
    model.add(InputLayer(input_shape = d.shape))
    model.add(Ident(NlastDim = d.shape[-1]))
    model.add(Projection(Nproj = Nproj))
    model.add(Dense(Nout, activation = 'linear'))
    model.compile(optimizer = 'adam', loss = 'mse', metrics=[tf.keras.metrics.RootMeanSquaredError()])

    prior = MyPrior(simModel['prior'])
    trainingGenerator = DataGenerator(simModel, N, NperBatch, Nbatches, prior)
    validationGenerator = DataGenerator(simModel, N, Nho, 1, prior)
    model.summary()
    model.fit(trainingGenerator, validation_data = validationGenerator)

The Ident and Projection layers are custom layers. Ident is defined to be an identity layer for debugging purposes. model.summary prints the model as follows


Model: "sequential"                                                                  _________________________________________________________________
 Layer (type)                Output Shape              Param #   
=================================================================                     ident (Ident)               (None, 2000, 3)           0         
                                                                  
projection (Projection)     (None, 4)                 0                                                                                               
dense (Dense)               (None, 2)                 10        
                                                                           
=================================================================                    Total params: 10 (40.00 Byte)   
Trainable params: 10 (40.00 Byte)                                                    
Non-trainable params: 0 (0.00 Byte)

However after this the Ident layer is called with

[Ident] call in-shape: (None, None, None)                   

After poking around it turns out that also a Dense layer, put first, gets called with this all None-shape. However, it can still provide an output defining the inner-most dimension based on the number of features specified. In my custom layers, I could not find a way to properly deal with this case. Using a placeholder results in:

    ValueError: Exception encountered when calling layer 'ident' (type Ident).
    
    in user code:
    
        File "/home/pingu/Documents/Projekte/2024-02-AutomaticStatistician self/src/./freqFlow.py", line 205, in call  *
            return tf.reshape(inputs, shape = inputs.shape[:-1] + (self.NlastDim,))
    
        ValueError: Tried to convert 'shape' to a tensor and failed. Error: Cannot convert a partially known TensorShape (None, None, 3) to a Tensor.
    
    
    Call arguments received by layer 'ident' (type Ident):
      • inputs=tf.Tensor(shape=(None, None, None), dtype=float32)

The Ident layer is defined as follows

class Ident(tf.keras.layers.Layer):
    def __init__(self, NlastDim = 1, **kwarks):
        super().__init__(**kwarks)
        self.NlastDim = NlastDim
        Log(2, f'[Ident] NlastDim={NlastDim}');
    def build(self, input_shape):
        Log(2, f'[Projection] build input_shape={input_shape}');
        super().build(input_shape)
    def call(self, inputs):
        Log(2, f'[Ident] call in-shape: {inputs.shape}')
        dimLast = inputs.shape[-1]
        if dimLast is None:
            return tf.reshape(inputs, shape = inputs.shape[:-1] + (self.NlastDim,))
        return inputs

I tried various solutions for dealing with the all-Nones by trying to implement compute_output_shape (which never gets called) or intercepting special cases in the code, trying to impose a defined inner-most dimension.
I did not expect a input tensor with all-Nones. I do use data generators for this model.

Thank you in advance.

New contributor

S Boehringer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật