Я написал простой файл TFRECORDS, содержащий три функции и метку. Поскольку я следую руководствам, мне кажется, что для использования этих TFRECORDS мне нужно создать набор данных, проанализировать примеры, сделать другие вещи, такие как нормализация с помощью map (). Если это неправильный рабочий процесс, я был бы признателен!
dataset = tf.data.TFRecordDataset("dataset.tfrecords")
#parse the protobuffer
def _parse_function(proto):
# define your tfrecord again.
keys_to_features = {'weight_pounds': tf.io.FixedLenFeature([], tf.float32),
'gestation_weeks': tf.io.FixedLenFeature([], tf.float32),
'plurality': tf.io.FixedLenFeature([], tf.float32),
'isMale': tf.io.FixedLenFeature([], tf.float32),
}
# Load one example
parsed_features = tf.io.parse_example(proto, keys_to_features)
# Turn your saved image string into an array
#parsed_features['image'] = tf.decode_raw(
# parsed_features['image'], tf.uint8)
return parsed_features
hold_meanstd={
'weight_pounds':[7.234738,1.330294],
'gestation_weeks':[38.346464,4.153269],
'plurality':[1.035285,0.196870]
}
def normalize(example):
example['weight_pounds']=(example['weight_pounds']-hold_meanstd['weight_pounds'][0])/hold_meanstd['weight_pounds'][1]
example['gestation_weeks']=(example['gestation_weeks']-hold_meanstd['gestation_weeks'][0])/hold_meanstd['gestation_weeks'][1]
example['plurality']=(example['plurality']-hold_meanstd['plurality'][0])/hold_meanstd['plurality'][1]
label=example.pop('isMale')
return(example,label)
dataset = tf.data.TFRecordDataset(["dataset.tfrecords"]).map(_parse_function)
dataset =dataset.map(normalize)
dataset =dataset.batch(64)
Затем, получив этот набор данных, я подумал, что могу использовать модель Keras:
Dense = keras.layers.Dense
model = keras.Sequential(
[
Dense(500, activation="relu", kernel_initializer='uniform',
input_shape=(3,)),
Dense(200, activation="relu"),
Dense(100, activation="relu"),
Dense(25, activation="relu"),
Dense(1, activation="sigmoid")
])
optimizer = keras.optimizers.RMSprop(lr=0.01)
# Compile Keras model
model.compile(loss='binary_crossentropy', optimizer=optimizer, metrics=[tf.keras.metrics.AUC()])
model.fit(dataset)
Это вызывает ошибку:
ValueError: Layer sequential_1 expects 1 inputs, but it received 3 input tensors. Inputs received: [<tf.Tensor 'ExpandDims:0' shape=(None, 1) dtype=float32>, <tf.Tensor 'ExpandDims_1:0' shape=(None, 1) dtype=float32>, <tf.Tensor 'ExpandDims_2:0' shape=(None, 1) dtype=float32>]
Кажется, проблема в том, что входной набор данных выглядит как три входа вместо одного? Как разрешить Керасу тренироваться на наборе данных TF RECORDS?