YiyanXu / DiFashion

Diffusion Models for Generative Outfit Recommendation
10 stars 0 forks source link

Diffusion Models for Generative Outfit Recommendation

This is the pytorch implementation of our paper at SIGIR 2024:

Diffusion Models for Generative Outfit Recommendation

Yiyan Xu, Wenjie Wang, Fuli Feng, Yunshan Ma, Jizhi Zhang, Xiangnan He

DiFashion Overview

An overview of DiFashion: it gradually corrupts outfit images with Gaussian noise in the forward process, followed by a parallel conditional denoising process to reconstruct these images. The denoising process is guided by three conditions: category prompt, mutual condition, and history condition. DiFashion Overview

Generated Examples

Environment

Usage

Dataset

The experimental data are in './datasets' folder, including iFashion and Polyvore-U. Each dataset consists of the following files:

For item images of iFashion,

  1. Download item information item_info.npy from here with the format:

    {
        iid1:{
            'original iid':ori_iid,
            'category':semantic_category,
            'url':image_url
        },
        ...
    }
  2. Download each image through the url into path '/img_folder_path/semantic_category/ori_iid.png', corresponding to the image path format in all_item_image_paths.npy.

  3. Process these item images via function process_image.

    from PIL import Image
    
    def process_image(image):
        image = convert_to_rgb(image)
        image = pad_to_square(image)
        target_size = (512, 512)
        image = resize_image(image, target_size)
    
        return image
    
    def convert_to_rgb(image):
        if image.mode != 'RGB':
            if image.mode != "RGBA":
                image = image.convert('RGBA')
            background = Image.new("RGBA", image.size, (255,255,255))
            result_image = Image.alpha_composite(background, image)
            result_image = result_image.convert("RGB")
    
            return result_image
        else:
            return image
    
    def pad_to_square(image):
        # Transform the image into a square format, ensuring a uniform white background.
        width, height = image.size
        padding = abs(width - height) // 2
    
        if width < height:
            padding_mode = (padding, 0)
        else:
            padding_mode = (0, padding)
    
        squared_image = Image.new('RGB', (max(width, height), max(width, height)), (255, 255, 255))
        squared_image.paste(image, padding_mode)
    
        return squared_image
    
    def resize_image(image, target_size):
        resized_image = image.resize(target_size, Image.LANCZOS)
    
        return resized_image
  4. Add an empty image into the image folder path without semantic category.

    from PIL import Image
    
    empty_img = Image.new('RGB', (512, 512), (255,255,255))  # a pure white image
    folder_path = '/img_folder_path/'
    empty_img.save(os.path.join(folder_path, "empty_image.png"))

For item images of Polyvore-U,

  1. Download all the images from here.
  2. Unzip the file 291x291.tar.gz and put it into an appropriate path '/path/to/291x291'.
  3. Add an empty image into the image folder.

    from PIL import Image
    
    empty_img = Image.new('RGB', (512, 512), (255,255,255))  # a pure white image
    folder_path = '/path/to/291x291'
    empty_img.save(os.path.join(folder_path, "empty_image.png"))

Training

Please configure correct paths of all data in train.py and set appropriate gpu id in config.yaml.

cd ./DiFashion
sh run_eta0.1.sh

Inference

  1. Download the checkpoint released by us from here.
  2. Put the checkpoint into appropriate folder.
  3. Configure correct paths of all data in inf4eval.py and set appropriate gpu id in config.yaml.
  4. Run inf4eval.py
    cd ./DiFashion
    sh run_inf4eval.sh

Evaluation

  1. Download finetuned inception from here and put it into '/Evaluation/finetuned_inception/'.
  2. Run the evaluation code through the .sh files. For example, to evaluate the performance of DiFashion on iFashion dataset within the Fill-In-The-Blank task, execute the corresponding evaluation code evaluate_fitb.py using the provided run_eval_fitb.sh.
    cd ./Evaluation
    sh run_eval_fitb.sh ifashion DiFashion all test log 3