Вычислить градиент в стремительном исполнении - PullRequest
0 голосов
/ 29 мая 2020

Я пытаюсь нарисовать карту внимания для изображения, которое было классифицировано моим CNN. Но я получаю сообщение

TypeError: объект 'NoneType' не может быть подписан

. Скажите, пожалуйста, если я что-то не так делаю.

import tensorflow as tf
 with tf.GradientTape() as tape:
    y_example=classifier6cb.predict(images)
    if y_example[0,0]==1.0:
        print("It's a cat")
    elif y_example[0,1]==1.0:
        print("It's a dog")
    else:
        print("Something is wrong")

    import numpy as np
    #Neuron corresponding to the predicted class
    neuron_num = np.argmax(y_example[0])

    # Prediction entry in the prediction vector
    model_output = classifier6cb.output[:, neuron_num]

    # The output feature map of the the last convolutional layer in the model
    #classifier6cb.summary()
    last_conv_layer = classifier6cb.get_layer('dense_2')

    # The gradient of the predicted class with regard to  the output feature map of `dense_2`
    from tensorflow.keras import backend as K
    grads = tape.gradient(model_output, last_conv_layer.output)[0]
...