Я получаю эту ошибку
ValueError: Tensor Tensor("gradients_3/conv2d_188/Conv2D_grad/Conv2DBackpropInput:0", shape=(None, 299, 299, 3), dtype=float32) не является элементом этого графика.
с кодом
import tensorflow as tf
import keras
import matplotlib.pyplot as plt
import numpy as np
from keras.applications.inception_v3 import InceptionV3, decode_predictions
from keras import backend as K
from keras.preprocessing import image
iv3 = InceptionV3()
x=image.img_to_array(image.load_img("Documents\PythonScripts\libro.jpg", target_size=(299,299)))
x /= 255
x -= 0.5
x *= 2
x = x.reshape([1 , x.shape[0], x.shape[1], x.shape[2]])
y=iv3.predict(x)
decode_predictions(y)
inp_layer = iv3.layers[0].input
out_layer = iv3.layers[-1].output
target_class = 951
loss = out_layer[0, target_class]
tf.compat.v1.disable_eager_execution()
grad = K.gradients(loss, inp_layer)[0]
optimize_gradient = K.function([inp_layer, K.learning_phase()],[grad, loss])
Где строка кода, вызвавшая ошибку? Что вы уже пробовали?
Ошибка: «K.function([inp_layer, K.learning_phase()],[град, потеря])». «Keras.function» не распознает
grad=K.gradients(loss, inp_layer)[0]
(тензор) как правильный параметр.