cuiaiyu / dressing-in-order

(ICCV'21) Official code of "Dressing in Order: Recurrent Person Image Generation for Pose Transfer, Virtual Try-on and Outfit Editing" by Aiyu Cui, Daniel McKee and Svetlana Lazebnik
https://cuiaiyu.github.io/dressing-in-order
Other
526 stars 129 forks source link

Results on custom images #83

Closed tyugv closed 1 year ago

tyugv commented 1 year ago

Hi! Thank you very much for your work!

I tried some garments from the demo notebook with an image of another person. These are my results: image image

image image

I noticed that clothing items look blurry compared to the ones from the notebook. Is it an expected result? image

Maybe the problem is in my code. I changed it to use try on with custom images

resize = transforms.Resize((256, 176))
toTensor = transforms.ToTensor()
toPIL = transforms.ToPILImage()
normalize = transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))

def load_img(dir):
  img = Image.open(dir).convert("RGB")
  img = resize(img)
  img = toTensor(img)
  img = normalize(img)
  return img

def load_mask(dir): 
  mask = Image.open(dir)
  mask = resize(mask)
  mask = torch.from_numpy(np.array(mask))

  texture_mask = copy.deepcopy(mask)
  for atr in atr2aiyu:
      aiyu = atr2aiyu[atr]
      texture_mask[mask == atr] = aiyu
  return texture_mask

def load_data(name):
    parse = load_mask(name + "_parsed.png")
    pimg = load_img(name + ".png")
    pose = load_pose_from_json(name + '_keypoints.json', target_size=(256, 176), orig_size=(256, 176))
    return pimg.cuda().squeeze(), parse.cuda().squeeze(), pose.cuda().squeeze()

# define dressing-in-order function (the pipeline)
def dress_in_order(model, pid, gids=[], ogids=[], order=[5,1,3,2]):
    PID = [0,4,6,7]
    GID = [2,5,1,3]
    # encode person
    pimg, parse, from_pose = load_data(pid)
    to_pose = from_pose
    psegs = model.encode_attr(pimg[None], parse[None], from_pose[None], to_pose[None], PID)

    # encode base garments
    gsegs = model.encode_attr(pimg[None], parse[None], from_pose[None], to_pose[None])

    # swap base garment if any
    gimgs = []
    for gid in gids:
        dir, k = gid
        gimg, gparse, pose =  load_data(dir)
        seg = model.encode_single_attr(gimg[None], gparse[None], pose[None], to_pose[None], i=k)
        gsegs[k] = seg
        gimgs += [gimg * (gparse == k)]

    # encode garment (overlay)
    garments = []
    over_gsegs = []
    oimgs = []
    for gid in ogids:
        dir, k = gid
        oimg, oparse, pose = load_data(dir)
        oimgs += [oimg * (oparse == k)]
        seg = model.encode_single_attr(oimg[None], oparse[None], pose[None], to_pose[None], i=k)
        over_gsegs += [seg]

    gsegs = [gsegs[i] for i in order] + over_gsegs
    gen_img = model.netG(to_pose[None], psegs, gsegs)

    return pimg, gimgs, oimgs, gen_img[0], to_pose
tyugv commented 1 year ago

Hi! Sorry for bothering, I figured it out. Earlier I resized all the images to small size before running the code but it is better to save them with resolution 750x1011 and then use transforms.Resize. For keypoints I changed orig size in load_pose_from_json like here https://github.com/cuiaiyu/dressing-in-order/issues/36#issuecomment-1047393508 . The result was a bit better this way. Also, I noticed that I had extra numbers in order when I called dress_in_order. It had a bad impact on the results. Here are my final results: Без названия (58) Без названия (60)

Vangari-Rajesh commented 2 days ago

can you give full code please