Ошибка значения при загрузке метрик в тензор потока? - PullRequest
0 голосов
/ 17 января 2020

Я получаю следующую ошибку при попытке построить сеть Keras LSTM-AttentionLayer, работающую с другими показателями, отличными от точности:

NotFoundError: Resource localhost/true_positives_15/class tensorflow::Var does not exist.
     [[{{node metrics_13/precision_8/AssignAddVariableOp}}]] 

Я использую версию Keras tenorflow с поддержкой версии 1.14.0 и импортирую следующие пакеты:

from tensorflow import keras   

from keras.preprocessing import sequence
from keras.models import Model, Input, Sequential
from keras.utils import to_categorical,plot_model

import tensorflow.keras.backend as K
import tensorflow as tf

from keras.layers import Input, Concatenate, Dropout, GRU, Bidirectional, Dense, Embedding, LSTM
from keras.engine.topology import Layer, InputSpec
from keras import initializers

from tensorflow.python.keras.metrics import AUC, Recall, Precision

(некоторые пакеты необходимы для создания слоя внимания.

Почему ошибка и как ее исправить?

xx = np.random.randint(100, size=(90,200,300))
y = np.random.randint(2, size=(90,1))

MAX_SENTS = 200
MAX_SENT_LENGTH = 300
EMBED_SIZE = 300

sent_input  = Input(shape=(MAX_SENTS, MAX_SENT_LENGTH))
l_lstm_sent = Bidirectional(LSTM(50, activation='tanh', return_sequences=True))(sent_input)
sent_dense = Dense(100, activation='relu', name='sent_dense')(l_lstm_sent) 
sent_att,sent_coeffs = AttentionLayer(EMBED_SIZE,return_coefficients=True,name='sent_attention')(sent_dense)
sent_drop = Dropout(0.5,name='sent_dropout')(sent_att)
preds = Dense(1, activation='softmax',name='output')(sent_drop)

model = Model(sent_input, preds)
model.compile(loss='binary_crossentropy',optimizer='adam',metrics=[Precision()])
history = model.fit(xx, y, epochs=5, batch_size=32) 
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...