Giter Site home page Giter Site logo

Question about heatmap about hpm HOT 3 CLOSED

haochen-wang409 avatar haochen-wang409 commented on May 25, 2024
Question about heatmap

from hpm.

Comments (3)

Haochen-Wang409 avatar Haochen-Wang409 commented on May 25, 2024

Thanks a lot for your attention!
Here is the pseudo-code for generating an RGB heatmap using the predicted reconstruction loss:

def show_loss_pred(model, inputs, img, num_patches=196, h=14, w=14, input_size=224):
    # generate a full visible mask
    mask = np.zeros((num_patches)).astype(bool)
    mask = torch.from_numpy(mask).unsqueeze(0).bool()

    with torch.no_grad():
        outs = model(inputs, mask)

    loss_show = outs['loss_pred'][0].cpu()

    # postprocessing for predicted loss
    loss_show = loss_show - loss_show.mean()
    loss_show = np.exp(loss_show) / (1 + np.exp(loss_show))
    loss_show = loss_show / loss_show.max()
    loss_show = (loss_show * 255).numpy().astype(np.uint8)

    reconstruct = loss_show.copy()

    reconstruct = reconstruct.reshape((h, w)).astype(np.uint8)
    reconstruct_color = cv2.applyColorMap(reconstruct, cv2.COLORMAP_JET)
    reconstruct_color = np.array(cv2.cvtColor(reconstruct_color, cv2.COLOR_BGR2RGB))

    rec_big = np.zeros((input_size, input_size, 3)).astype(np.uint8)
    for i in range(h):
        for j in range(w):
            rec_big[i * 16: i * 16 + 16, j * 16: j * 16 + 16, :] = reconstruct_color[i, j]

    img = np.array(img)
    img_show = (0.5 * img + 0.5 * rec_big).astype(np.uint8)

    return img_show

from hpm.

Lrbomchz avatar Lrbomchz commented on May 25, 2024

Thank you very much, itβ€˜s work!

from hpm.

Haochen-Wang409 avatar Haochen-Wang409 commented on May 25, 2024

Happy to hear that :)
I hope our work brings inspiration to you.

from hpm.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.