![]() gradient ( class_channel, last_conv_layer_output ) # This is a vector where each entry is the mean intensity of the gradient # over a specific feature map channel pooled_grads = tf. argmax ( preds ) class_channel = preds # This is the gradient of the output neuron (top predicted or chosen) # with regard to the output feature map of the last conv layer grads = tape. GradientTape () as tape : last_conv_layer_output, preds = grad_model ( img_array ) if pred_index is None : pred_index = tf. Model (, ) # Then, we compute the gradient of the top predicted class for our input image # with respect to the activations of the last conv layer with tf. expand_dims ( array, axis = 0 ) return array def make_gradcam_heatmap ( img_array, model, last_conv_layer_name, pred_index = None ): # First, we create a model that maps the input image to the activations # of the last conv layer as well as the output predictions grad_model = tf. img_to_array ( img ) # We add a dimension to transform our array into a "batch" # of size (1, 299, 299, 3) array = np. load_img ( img_path, target_size = size ) # `array` is a float32 Numpy array of shape (299, 299, 3) array = keras. Def get_img_array ( img_path, size ): # `img` is a PIL image of size 299x299 img = keras. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |