[Python] Confused by keras/tensorflow error: ValueError: None values not supported

Discussão em 'Python' iniciado por Stack, Novembro 29, 2024.

  1. Stack

    Stack Membro Participativo

    I'm trying to build a neural net in tensorflow/keras but I'm stuck on this error:

    ValueError: None values not supported.


    I've been able to reduce the code to reproduce this to the following mock example:

    from tensorflow.keras import layers, Model, Input
    from tensorflow.keras.models import Sequential
    import pandas as pd
    import numpy as np
    import tensorflow as tf

    input_data = pd.DataFrame(np.random.rand(1000, 10))

    data = tf.data.Dataset.zip({'input_values' : tf.data.Dataset.from_tensor_slices(input_data.values)})

    batch_size = 100
    train_split = 0.8

    train_rows = int(train_split * input_data.shape[0])
    train_dataset = data.take(train_rows)
    validation_dataset = data.skip(train_rows)

    train_data_batched = train_dataset.batch(batch_size).prefetch(tf.data.AUTOTUNE)
    validation_data_batched = validation_dataset.batch(batch_size).prefetch(tf.data.AUTOTUNE)

    num_outputs = 10

    input_layer = Input(shape=(num_outputs,), name=f'input_values')
    output = layers.Dense(num_outputs, activation='sigmoid', name='output')(input_layer)

    # Define the model
    model = Model(
    inputs=[input_layer],
    outputs=output,
    )

    max_epochs = 10

    def loss(y_true, y_pred):
    return 2.0

    model.compile(
    loss=loss,
    optimizer='adam',
    )

    history = model.fit(
    train_data_batched,
    epochs=max_epochs,
    validation_data=validation_data_batched
    )


    Here is the full error:

    File /tmp/virtualenvs/python3.11/lib/python3.11/site-packages/keras/src/utils/traceback_utils.py:122, in filter_traceback.<locals>.error_handler(*args, **kwargs)
    119 filtered_tb = _process_traceback_frames(e.__traceback__)
    120 # To get the full stack trace, call:
    121 # `keras.config.disable_traceback_filtering()`
    --> 122 raise e.with_traceback(filtered_tb) from None
    123 finally:
    124 del filtered_tb

    File /tmp/virtualenvs/python3.11/lib/python3.11/site-packages/optree/ops.py:752, in tree_map(func, tree, is_leaf, none_is_leaf, namespace, *rests)
    750 leaves, treespec = _C.flatten(tree, is_leaf, none_is_leaf, namespace)
    751 flat_args = [leaves] + [treespec.flatten_up_to(r) for r in rests]
    --> 752 return treespec.unflatten(map(func, *flat_args))

    ValueError: None values not supported.


    But I'm stuck as to what to do, mainly because I don't understand what the error is referring to (None values where? In a tensor? In a shape? Somewhere else?)

    I'm running tensorflow[and-cuda]==2.18.0

    Continue reading...

Compartilhe esta Página