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
529 stars 129 forks source link

Testing on CPU #58

Closed vinodbukya6 closed 2 years ago

vinodbukya6 commented 2 years ago

Hi @cuiaiyu, Thank you so much for your work. I am running demo.ipynb on CPU machine for virtual tryon. Facing AttributeError: 'ADGANEncoder' object has no attribute 'module'

Can you help me on the same.

cuiaiyu commented 2 years ago

I personally never tried the code on CPU, but my intuition is to try call it without module attribute (by something like netE_attr.enc_seg() rather than netE_attr.module.enc_seg()), because the _init_net() wouldn't send model to parallel if there is no GPU, so no the models don't have module.

vinodbukya6 commented 2 years ago

Hi @cuiaiyu . Thank you so much for response.

I have converted code GPU to CPU by changing here:

def init_net(net, init_type='normal', init_gain=0.02, gpu_ids=[], do_init_weight=True):
    """Initialize a network: 1. register CPU/GPU device (with multi-GPU support); 2. initialize the network weights
    Parameters:
        net (network)      -- the network to be initialized
        init_type (str)    -- the name of an initialization method: normal | xavier | kaiming | orthogonal
        gain (float)       -- scaling factor for normal, xavier and orthogonal.
        gpu_ids (int list) -- which GPUs the network runs on: e.g., 0,1,2
    Return an initialized network.
    """

    if torch.cuda.is_available():
        device = torch.device("cuda")
    else:
        device = torch.device("cpu")

    gpu_ids = [0]

    if len(gpu_ids) > 0:
        # import pdb; pdb.set_trace()
        #assert(torch.cuda.is_available())

        net = net.cpu()
        net.to(device)
        net = torch.nn.DataParallel(net, device_ids=None)  # multi-GPUs

    if do_init_weight:
        init_weights(net, init_type, init_gain=init_gain)
    return net

But facing poor performance issue. Will this affect the performance or am I doing anything wrong?

Sample Output Image: download3

cuiaiyu commented 2 years ago

I’m not sure if it causes any changes by running on CPU.

However, you may want to check if the keypoint is loaded correctly as well, the color of joints and the lines between the joints are not what to expect.

On Aug 22, 2022, at 11:48 PM, BUKYA VINOD @.***> wrote:

 Hi @cuiaiyu . Thank you so much for response.

I have converted code GPU to CPU by changing here:

def init_net(net, init_type='normal', init_gain=0.02, gpu_ids=[], do_init_weight=True): """Initialize a network: 1. register CPU/GPU device (with multi-GPU support); 2. initialize the network weights Parameters: net (network) -- the network to be initialized init_type (str) -- the name of an initialization method: normal | xavier | kaiming | orthogonal gain (float) -- scaling factor for normal, xavier and orthogonal. gpu_ids (int list) -- which GPUs the network runs on: e.g., 0,1,2 Return an initialized network. """

if torch.cuda.is_available():
    device = torch.device("cuda")
else:
    device = torch.device("cpu")

gpu_ids = [0]

if len(gpu_ids) > 0:
    # import pdb; pdb.set_trace()
    #assert(torch.cuda.is_available())

    net = net.cpu()
    net.to(device)
    net = torch.nn.DataParallel(net, device_ids=None)  # multi-GPUs

if do_init_weight:
    init_weights(net, init_type, init_gain=init_gain)
return net

But facing poor performance issue. Will this affect the performance or am I doing anything wrong?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.

vinodbukya6 commented 2 years ago

Hi @cuiaiyu Thank you for your quick response. Performance is same as GPU based code.

But I am not able to fetch the Garment images. sample image download3

Getting Garment image like this. download4

I have modified the code as below:

def dress_in_order(pimg,parse,from_pose,to_pose, gimg,gparse,pose):
    PID = [0,4,6,7]
    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
    gids = [("plaid",0,5)] # 5-top, 1-bottom
    gimgs = []
    for gid in gids:
        _,_,k = gid
        #gimg, gparse, pose =  load_img(gid, ds)
        seg = model.encode_single_attr(gimg[None], gparse[None], pose[None], to_pose[None], i=gid[2])
        gsegs[gid[2]] = seg
        gimgs += [gimg * (gparse == gid[2]).to(torch.float32)]

    order=[2,5,1] # not tuckin (dressing order: hair, bottom, top)    
    gsegs = [gsegs[i] for i in order]
    gen_img = model.netG(to_pose[None], psegs, gsegs)

    return pimg, gimgs, gen_img[0], to_pose

What am I missing here. Can you help me on this.