В качестве названия я получаю ошибку:
ValueError: Expected scalar shape for SparseSoftmaxCrossEntropyWithLogits/SparseSoftmaxCrossEntropyWithLogits:0, saw shape: (52692,).
Формы, которые я передаю:
логиты - [52692, 4] - ранг 2
этикетки - [52692] - ранг 1
Есть 4 класса
Вот как я передаю свои данные модели в основном кортеж (функции, метки)
def _input_fn(training_dir, training_filename):
def getFeatureLabelOH(file):
features, labels = csvGetColumns(file)
count = len(features)
# converting features and labels to integers
featuresVec, labelsVec = convCharToVec(features, alphabetDict, maxFeatureLen), \
[conventions[label] for label in labels]
featuresVec = tf.convert_to_tensor(featuresVec, dtype=tf.int32)
labelsVec = tf.convert_to_tensor(labelsVec, dtype=tf.int32)
labelsVec = tf.reshape(labelsVec, [-1])
return {"featuresVec": featuresVec, "labelsVec": labelsVec, "count": count}
data = getFeatureLabelOH(os.path.join(training_dir,
return (data["featuresVec"], data["labelsVec"])
И моя фактическая модель
def model_fn(features, labels, mode, params):
net = keras.layers.Embedding(alphabetLen + 1, 8, input_length=maxFeatureLen)(features)
net = keras.layers.LSTM(12)(net)
logits = keras.layers.Dense(len(conventions), activation=tf.nn.softmax)(net) #output
loss = tf.nn.sparse_softmax_cross_entropy_with_logits(labels=labels, logits=logits)
train_op = tf.contrib.layers.optimize_loss(
loss=loss,
global_step=tf.train.get_global_step(),
learning_rate=0.001,
optimizer="AdamOptimizer")
eval_metric_ops = {}
return tf.estimator.EstimatorSpec(
mode=mode,
loss=loss,
train_op=train_op,
eval_metric_ops=eval_metric_ops)