问题
i am trying to preprocess and classify iris dataset using tensorflow piplines, but after the preprocessing i've got this error: Unsupported return value from function passed to Dataset.map(): (, NumericColumn(key='features', shape=(4,), default_value=None, dtype=tf.float32, normalizer_fn=None)), i am stuck un there, il'll be happy for any helpe here's the complete code of the DNN
import tensorflow_datasets as tfds
from tensorflow.keras.optimizers import Adam
data = tfds.load("iris", split=tfds.Split.TRAIN)
def preprocess(features):
# should return features and one-hot encoded labels
#l = tf.feature_column.categorical_column_with_identity("label", 3, default_value=None)
l = tf.one_hot(features["label"], 3)
f = tf.feature_column.numeric_column("features", shape=(4,), dtype=tf.dtypes.float32)
return l, f
def solution_model():
train_dataset = data.map(preprocess).batch(10)
dataset_layer = tf.keras.layers.DenseFeatures(train_dataset)
# YOUR CODE TO TRAIN A MODEL
model = tf.keras.Sequential([
dataset_layer,
tf.keras.layers.Dense(32, input_shape=(None,4)),
tf.keras.layers.Dense(64, activation=tf.nn.relu),
tf.keras.layers.Dense(3, activation=tf.nn.softmax)
])
print(model.summary)
#model.compile(optimizer="sgd", loss="mean_squared_error")
model.compile(loss=tf.keras.losses.categorical_crossentropy,
optimizer=tf.keras.optimizers.SGD(
learning_rate=0.01, momentum=0.0, nesterov=False, name='SGD'),
metrics=['accuracy'])
model.fit(train_dataset, epochs=100)
return model
if __name__ == '__main__':
model = solution_model()
model.save('mymodel.h5')```
来源:https://stackoverflow.com/questions/61669745/unsupported-return-value-from-function-passed-to-dataset-map