Skip to main content

Generating synthetic polyps and corresponding mask using pretrained SinGAN-Seg and Style tranfering functionalities.

Project description

singan-polyp-aug

Install pip singan-polyp-aug

pip install singan-polyp-aug

Import required packages

from singan_polyp_aug import generate_data, prepare_requirements

Prepare checkpoints

>>> help(prepare_requirements.prepare_checkpoints)
Help on function prepare_checkpoints in module singan_polyp_aug.prepare_requirements:

prepare_checkpoints(path_to_checkpoints: str, link_keys=["link1", "link2", "link3", "link4"], real_data=True, *args, **kwargs) -> str
out_paths = prepare_requirements.prepare_checkpoints("./singan_polyp_checkpoints", link_keys=["link1", "link2", "link3", "link4"])

Parameters

  • path_to_checkpoints -- A path to save checkpoints. The prepare_checkpoints() function checks the availability of pre-downloaded checkpoints. So, the use can run the save command twice without any downlaod overhead.

  • link_keys -- A list of pre-defined keys to download links. To download the full checkpoint list, use link_keys=["link1", "link2", "link3", "link4"]. If the user needs only a half of check points, then, the user can use only a half of link_keys. For example, link_keys= ["link1", "link2"]

  • real_data -- If this is True, real images and masks used to train SinGANs will be downloaded into the checkpoint folder.

Return

This function returns a list of paths to all downloaded checkpoints to use with other functions of singan_polyp_aug. If the all checkpoints are used, then the function returns 1000 different sinGAN checkpoint paths which are dirrecting to pre-trained SinGAN checkpoints of the 1000 polyp images introduced in Hyper-kvasir dataset.


Generate synthetic polyps and corresponding mask

generate_data.generate_from_single_checkpoint(out_dir:str, 
                                    checkpoint_path:str, 
                                    num_samples:int=1, 
                                    gen_start_scale:int=5,
                                    mask_post_processing:bool=True) -> None:
    ''' A function to generate synthetic polyp and correspondign mask from a given checkpoint path.

    Parameters
    ----------
    out_dir: str
        A path to save output data.
    checkpoint_path: str
        A path to a downloaded checkpoint. To get paths, you have to run prepare_requirements.prepare_checkpoints() function.
    num_samples: int
        Number of random samples to generate from the given checkpoint. Default=1.
    gen_start_scale: int
        Predefined scales used in SinGAN training. You can use values between 0-9. Value 0 generates more random samples and value 9 generate sampels which are 
        very close to the training image.
    mask_post_processing: bool
        Whether the generated mask should be post processed or not. If True, generates mask is cleaned to have only 0 and 255. 

    Returns
    ------
    None
        This function does not have a return. 

    '''
generate_data.generate_from_multiple_checkpoints(out_dir:str, checkpoint_paths:list, *args, **kwargs)-> None:
    ''' A function to generate synthetic polyp and correspondign mask from a given list of checkpoint paths.

    Parameters
    ----------
    out_dir: str
        A path to save output data.
    checkpoint_paths: list
        A path list to downloaded checkpoints. To get paths, you have to run prepare_requirements.prepare_checkpoints() function.
    num_samples: int
        Number of random samples to generate from the given checkpoint. Default=1.
    gen_start_scale: int
        Predefined scales used in SinGAN training. You can use values between 0-9. Value 0 generates more random samples and value 9 generate sampels which are 
        very close to the training image.
    mask_post_processing: bool
        Whether the generated mask should be post processed or not. If True, generates mask is cleaned to have only 0 and 255. 

    Returns
    ------
    None
        This function does not have a return. 

    '''
generate_data.generate_simple(out_dir:str, chk_dir:str, *args, **kwargs)-> None:
    ''' A function to generate synthetic polyp and correspondign mask from all downloaded checkpoint paths.

    Parameters
    ----------
    out_dir: str
        A path to save output data.
    chk_dir: str
        The path to checkpoint directory. If the directory does not have downloaded checkpoints, this function will download them.
    num_samples: int
        Number of random samples to generate from the given checkpoint. Default=1.
    gen_start_scale: int
        Predefined scales used in SinGAN training. You can use values between 0-9. Value 0 generates more random samples and value 9 generate sampels which are 
        very close to the training image.
    mask_post_processing: bool
        Whether the generated mask should be post processed or not. If True, generates mask is cleaned to have only 0 and 255. 

    Returns
    ------
    None
        This function does not have a return. 

    '''

Simple generation function


Citation:

TBA

References:


@article{cite-key,
	da = {2020/08/28},
	date-added = {2021-03-27 01:08:18 +0100},
	date-modified = {2021-03-27 01:08:18 +0100},
	doi = {10.1038/s41597-020-00622-y},
	id = {Borgli2020},
	isbn = {2052-4463},
	journal = {Scientific Data},
	number = {1},
	pages = {283},
	title = {HyperKvasir, a comprehensive multi-class image and video dataset for gastrointestinal endoscopy},
	ty = {JOUR},
	url = {https://doi.org/10.1038/s41597-020-00622-y},
	volume = {7},
	year = {2020},
	Bdsk-Url-1 = {https://doi.org/10.1038/s41597-020-00622-y}}

@inproceedings{shaham2019singan,
  title={Singan: Learning a generative model from a single natural image},
  author={Shaham, Tamar Rott and Dekel, Tali and Michaeli, Tomer},
  booktitle={Proceedings of the IEEE/CVF International Conference on Computer Vision},
  pages={4570--4580},
  year={2019}
}

Contacts:

vajira@simula.no or michael@simula.no

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

singan-seg-polyp-1.0.0.tar.gz (25.4 kB view details)

Uploaded Source

Built Distribution

singan_seg_polyp-1.0.0-py3-none-any.whl (27.5 kB view details)

Uploaded Python 3

File details

Details for the file singan-seg-polyp-1.0.0.tar.gz.

File metadata

  • Download URL: singan-seg-polyp-1.0.0.tar.gz
  • Upload date:
  • Size: 25.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.8

File hashes

Hashes for singan-seg-polyp-1.0.0.tar.gz
Algorithm Hash digest
SHA256 e82d159fc72077c3077abe04814d870ebc3b75f585250b5aa49c51775d66c47f
MD5 4d90b16d2df5005ea061c94fa4e56192
BLAKE2b-256 606c2b2049a290588a8b12f5c24c43e9e1b633349157ae5ca535c4892f61f6ad

See more details on using hashes here.

File details

Details for the file singan_seg_polyp-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: singan_seg_polyp-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 27.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.8

File hashes

Hashes for singan_seg_polyp-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 da956852b71bdedd41979f085c5889dbddb9699cdaa28aa25b12a48dc92ee495
MD5 74125534ddce739640a74da10c0fa6bd
BLAKE2b-256 85c97f3b5f4870548c9c09908492d11a74e2e103c308e46fda41f18a6c4c7fea

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page