Error: None values not supported

No matter how I change my model, there always a error happens

# import os
# import numpy as np
#
# from utils import read
# from DenseNet import ConvDense, DenseBlock
# from Loss import CombinedLoss

import tensorflow as tf


def train():
    # path_list = [os.path.join('train-for-densenet', path) for path in os.listdir('train-for-densenet')]
    # print(type(path_list))
    # path_dataset = tf.data.Dataset.from_tensor_slices(path_list)
    # print(path_dataset)
    # dataset = path_dataset.map(lambda path: read(path)).take(10)
    # for e in dataset:
    #     e = tf.ones([256, 256, 1], dtype=tf.float32)
    #     print(e)
    # print(dataset.batch(2))
    dataset = tf.ones([10, 256, 256, 1], dtype=tf.float32)
    dataset = tf.data.Dataset.from_tensor_slices(dataset)
    for e in dataset:
        print(e)
    print(dataset)
    model = tf.keras.models.Sequential([
        # tf.keras.layers.Rescaling(1. / 255),
        # ConvDense(16),
        # DenseBlock(),
        # ConvDense(64),
        # ConvDense(32),
        # ConvDense(16),
        # ConvDense(1),
        tf.keras.layers.Dense(10, activation='sigmoid')
    ])
    # combined_loss = CombinedLoss(weight_ssim=0.7)
    model.compile(
        optimizer='Adam',
        loss=tf.keras.losses.CategoricalCrossentropy
    )
    # model.build(input_shape=(None, 256, 256, 1))
    try:
        model.fit(
            dataset,
            epochs=4
        )
    except Exception as e:
        print("Error:", e)

    print(model.summary())


if __name__ == '__main__':
    train()

I customize my model and try to train it but find this error. I think that my model have some problems, but it still has same error after I use Sequtial model with keras.layers.

Hi @user520,

  • I have reproduced your code and the error is mainly due to dataset representation. You need to provide corresponding output labels along with input data. Please check the changes in the following code snippet .
    dataset = tf.ones([10, 256, 256, 1], dtype=tf.float32)
    labels = tf.one_hot(tf.range(10) % 10, depth=10)  # added Dummy one-hot encoded labels
    dataset = tf.data.Dataset.from_tensor_slices((dataset, labels)).batch(2)
  • It’s recommended to specify input , flatten layer along with dense layer in your model architecture.
tf.keras.layers.InputLayer(shape=(256, 256, 1)),   #input_shape() depricated
        tf.keras.layers.Conv2D(32, (3, 3), activation='relu'),
        tf.keras.layers.MaxPooling2D(),
        tf.keras.layers.Flatten(),
        tf.keras.layers.Dense(10, activation='sigmoid')

Please refer to the gist for working code.

Thank You

Thank you, I realized it.