scripts/attention_analyzer.py
def add_alphalayer(image, alpha, concatenate=True):    
    """
    Returns a numpy array with original image + overalayed
    """
    # alpha is here a 49-dim vector
    image = cv2.resize(image, (224, 224))
    img = numpy.array(image)
    alphalayer = numpy.ones((224,224,1))*255
    img = numpy.dstack((img,alphalayer)) #rgba

    # create the attention map and add an Alpha layer to the RGB image
    # 7*32 = 224 must upscale to original image 
    alpha_img = skimage.transform.pyramid_expand(alpha.reshape(7,7), upscale=32, sigma=20)
    alpha_img = alpha_img*255.0/numpy.max(alpha_img)
    alpha_img = skimage.color.gray2rgb(alpha_img)
    alpha_img = numpy.dstack((alpha_img,0.8*alphalayer)) #rgba

    old_img = img
    img = overlay(img,alpha_img)
    if concatenate:
        img  = numpy.concatenate((old_img,img),axis=1) # axis=0) 
    return img

    Returns a numpy array with original image + overalayed
    
Returns a numpy array with original image + overalayed
Returns a numpy array with original image + overalayed
def add_alphalayer(image, alpha, concatenate=True):    
    image = cv2.resize(image, (224, 224))
    img = numpy.array(image)
    alphalayer = numpy.ones((224,224,1))*255
    img = numpy.dstack((img,alphalayer)) 
    alpha_img = skimage.transform.pyramid_expand(alpha.reshape(7,7), upscale=32, sigma=20)
    alpha_img = alpha_img*255.0/numpy.max(alpha_img)
    alpha_img = skimage.color.gray2rgb(alpha_img)
    alpha_img = numpy.dstack((alpha_img,0.8*alphalayer)) 
    old_img = img
    img = overlay(img,alpha_img)
    if concatenate:
        img  = numpy.concatenate((old_img,img),axis=1) 
    return img
def add_alphalayer ( image , alpha , concatenate = True ) : image = cv2 . resize ( image , ( 224 , 224 ) ) img = numpy . array ( image ) alphalayer = numpy . ones ( ( 224 , 224 , 1 ) ) * 255 img = numpy . dstack ( ( img , alphalayer ) ) alpha_img = skimage . transform . pyramid_expand ( alpha . reshape ( 7 , 7 ) , upscale = 32 , sigma = 20 ) alpha_img = alpha_img * 255.0 / numpy . max ( alpha_img ) alpha_img = skimage . color . gray2rgb ( alpha_img ) alpha_img = numpy . dstack ( ( alpha_img , 0.8 * alphalayer ) ) old_img = img img = overlay ( img , alpha_img ) if concatenate : img = numpy . concatenate ( ( old_img , img ) , axis = 1 ) return img
Returns a numpy array with original image + overalayed
Returns a numpy array with original image + overalayed
"""
    Returns a numpy array with original image + overalayed
    """ # alpha is here a 49-dim vector #rgba # create the attention map and add an Alpha layer to the RGB image # 7*32 = 224 must upscale to original image  #rgba # axis=0) 
image
alpha
concatenate