GithubHelp home page GithubHelp logo

Comments (2)

LZRZJUT avatar LZRZJUT commented on July 28, 2024 2

Thank you very much for your help, but in fact I had already read this issue before I asked this question.
Just now I've changed the code and it works, and I'll put up my code as well.

def resize(img, height, width, centerCrop=True):
    imgh, imgw = img.shape[0:2]

    if centerCrop and imgh != imgw:
        # center crop
        side = np.minimum(imgh, imgw)
        j = (imgh - side) // 2
        i = (imgw - side) // 2
        img = img[j:j + side, i:i + side, ...]

    img = np.array(Image.fromarray(img).resize((height,width)))

    return img

def load_mask(imgh, imgw):
    mask = imread('./image/in/2409_mask.png')   # mask must be 255 for hole in this InpaintingModel
    mask = resize(mask, imgh, imgw, centerCrop=False)
    #mask = rgb2gray(mask)
    mask = (mask > 0).astype(np.uint8) * 255       # threshold due to interpolation
    mask = 255 - mask
    return to_tensor(mask)

def to_tensor(img):
    img = Image.fromarray(img)
    img_t = torchvision.transforms.functional.to_tensor(img).float()
    return img_t





source_mask_64 = load_mask(64, 64)
source_mask_256 = load_mask(256, 256)

With the above code you can load a mask image of your own, but of course you can also modify the function to make it more convenient。
Thanks again!
Have a nice day!

from glide-text2im.

woctezuma avatar woctezuma commented on July 28, 2024

from glide-text2im.

Related Issues (20)

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.