Exemple #1
0
def generate_texture_on_mask_final(outfit_feat_dict, updated_feature):
    ''' Generate updated texture on updated mask from updated feature
        Args: outfit_feat_dict (python dict), original texture feature in the format for cGAN to decode
              updated_feature (list of InputFeature objects), classifier input feature after updating
    '''
    parentPath = os.path.abspath(f'{ROOT_DIR}/generation')
    if parentPath not in sys.path:
        sys.path.insert(1, parentPath)
    from decode_clothing_features import generation_from_decoded_mask

    # Generation for final update
    iter_outfit_feat_dict = copy.deepcopy(outfit_feat_dict)
    feature = updated_feature[-1]  # Last feature is the final update
    if argopt.update_full:
        raise NotImplementedError
    else:
        iter_outfit_feat_dict[swapped_type] = np.expand_dims(
            feature.get_feature(swapped_partID, mode='texture_only'), axis=0)
    with cd(f'{ROOT_DIR}/generation'):
        generation_from_decoded_mask('final', argopt.save_dir, fname, iter_outfit_feat_dict, \
                                    argopt.load_pretrain_texture_gen, argopt.color_mode, argopt.netG, argopt.model_type, argopt.classname, argopt.texture_feat_num, original_mask=False, update=True, from_avg=True, remove_background=True)
    # Reconstruct original image before updating
    iter_outfit_feat_dict = copy.deepcopy(outfit_feat_dict)
    with cd(f'{ROOT_DIR}/generation'):
        generation_from_decoded_mask('001', argopt.save_dir, fname, iter_outfit_feat_dict, \
                                    argopt.load_pretrain_texture_gen, argopt.color_mode, argopt.netG, argopt.model_type, argopt.classname, argopt.texture_feat_num, original_mask=False, update=True, from_avg=True, remove_background=True)
    # Remove generator path
    if parentPath in sys.path:
        sys.path.remove(parentPath)
Exemple #2
0
def generate_texture_on_mask_per_iteration(outfit_feat_dict, updated_feature):
    ''' Generate updated texture on updated mask from updated feature
        Args: outfit_feat_dict (python dict), original texture feature in the format for cGAN to decode
              updated_feature (list of InputFeature objects), classifier input feature after updating
    '''
    parentPath = os.path.abspath(f'{ROOT_DIR}/generation')
    if parentPath not in sys.path:
        sys.path.insert(1, parentPath)
    from decode_clothing_features import generation_from_decoded_mask

    for iter in range(len(updated_feature)):
        iter_outfit_feat_dict = copy.deepcopy(outfit_feat_dict)
        feature = updated_feature[iter]
        if argopt.update_full:
            raise NotImplementedError
        else:
            iter_outfit_feat_dict[swapped_type] = np.expand_dims(
                feature.get_feature(swapped_partID, mode='texture_only'),
                axis=0)
        with cd(f'{ROOT_DIR}/generation'):  # WRITE A BATCH VERSION LATER
            generation_from_decoded_mask('%03d' % ((iter + 1) * argopt.display_freq), argopt.save_dir, fname, iter_outfit_feat_dict, \
                                        argopt.load_pretrain_texture_gen, argopt.color_mode, argopt.netG, argopt.model_type, argopt.classname, argopt.texture_feat_num, original_mask=False, update=True, from_avg=True, remove_background=True)
    # Remove generator path
    if parentPath in sys.path:
        sys.path.remove(parentPath)