adversarials.core package

Submodules

adversarials.core.arch module

Architecture of SimpleGAN for Adversarial package. @author

Domnan Diretnan Artificial Intelligence Enthusiast & Python Developer Email: diretnandomnan@gmail.com GitHub: https://github.com/deven96

@project

File: arch.py

@license

MIT License Copyright (c) 2018. Domnan Diretnan. All rights reserved.

class adversarials.core.arch.SimpleGAN(size: Union[Tuple[int], int] = 28, channels: int = 1, batch_size: int = 32, **kwargs)

Bases: adversarials.core.base.ModelBase

Simple Generative Adversarial Network.

Methods:

def __init__(self, size: Union[Tuple[int], int]=28, channels: int=1, batch_size: int=32, **kwargs)

def train(self, X_train, epochs: int=10):

def plot_images(self, samples: int=16, step:int=0):

# Plot generated images

Attributes:

G (keras.model.Model): Generator model. D (keras.model.Model): Discriminator model. model (keras.model.Model): Combined G & D model. shape (Tuple[int]): Input image shape.

call(n: int = 1, dim: int = 100)

Inference method. Given a random latent sample. Generate an image.

Args:
samples (int, optional): Defaults to 1. Number of images to

be generated.

dim (int, optional): Defaults to 100. Noise dimension.

Returns:

np.ndarray: Array-like generated images.

property model

Stacked generator-discriminator model.

Returns:

keras.model.Model: Combined G & D model.

plot_images(samples=16, step=0)

Plot and generate images

samples (int, optional): Defaults to 16. Noise samples to generate. step (int, optional): Defaults to 0. Number of training step currently.

property shape

Input image shape.

Returns:

Tuple[int]: image shape.

train(X_train, epochs: int = 10)

Train function to be used after GAN initialization

X_train[np.array]: full set of images to be used

adversarials.core.base module

Base classes for Adversarial package.

@author

Victor I. Afolabi Artificial Intelligence Expert & Software Engineer. Email: javafolabi@gmail.com | victor.afolabi@zephyrtel.com GitHub: https://github.com/victor-iyiola

@project

File: base.py Created on 20 December, 2018 @ 06:56 PM.

@license

MIT License Copyright (c) 2018. Victor I. Afolabi. All rights reserved.

class adversarials.core.base.ModelBase(*args, **kwargs)

Bases: adversarials.core.base._Base

property cache_dir
abstract call(*args, **kwargs)
static int_shape(x)

Returns the shape of tensor or variable as tuple of int or None entries.

Args:

x (Union[tf.Tensor, tf.Variable]): Tensor or variable. hasattr(x, ‘shape’)

Returns:

tuple: A tuple of integers (or None entries).

adversarials.core.config module

Configuration file for Adversarial package.

@author

Victor I. Afolabi Artificial Intelligence Expert & Software Engineer. Email: javafolabi@gmail.com | victor.afolabi@zephyrtel.com GitHub: https://github.com/victor-iyiola

@project

File: config.py.py Created on 20 December, 2018 @ 07:07 PM.

@license

MIT License Copyright (c) 2018. Victor I. Afolabi. All rights reserved.

class adversarials.core.config.Config

Bases: object

static from_cfg(file: str, ext: str = 'cfg')

Load configuration from an cfg file.

Args:

file (str): An cfg filename. ext (str, optional): Defaults to ‘cfg’. Config file extension.

Raises:

AssertionError: File is not an ${ext} file. FileNotFoundError: file was not found.

Returns:

easydict.EasyDict: config dictionary object.

static from_json(file: str)

Load configuration from a json file.

Args:

file (str): A JSON filename.

Raises:

AssertionError: File is not a JSON file. FileNotFoundError: file was not found.

Returns:

easydict.EasyDict: config dictionary object.

static from_yaml(file: str)

Load configuration from a YAML file.

Args:

file (str): A .yml or .yaml filename.

Raises:

AssertionError: File is not a YAML file. FileNotFoundError: file was not found.

Returns:

easydict.EasyDict: config dictionary object.

static to_cfg(cfg: easydict.EasyDict, file: str, **kwargs)

Save configuration object into a cfg or ini file.

Args:

cfg (Any): Configuration: as dictionary instance. file (str): Path to write the configuration to.

Keyword Args:

Passed into dumper.

static to_json(cfg: easydict.EasyDict, file: str, **kwargs)

Save configuration object into a JSON file.

Args:

cfg (EasyDict): Configuration: as dictionary instance. file (str): Path to write the configuration to.

Keyword Args:

Passed into dumper.

Raises:

AssertionError: dumper must be callable.

static to_pickle(cfg: Any, file: str, **kwargs)

Save configuration object into a pickle file.

Args:

cfg (Any): Configuration: as dictionary instance. file (str): Path to write the configuration to.

Keyword Args:

Passed into dumper.

Raises:

AssertionError: dumper must be callable.

static to_yaml(cfg: easydict.EasyDict, file: str, **kwargs)

Save configuration object into a YAML file.

Args:

cfg (EasyDict): Configuration: as a dictionary instance. file (str): Path to write the configuration to.

Keyword Args:

Passed into dumper.

Raises:

AssertionError: dumper must be callable.

adversarials.core.consts module

Constants for Adversarial package.

@author

Victor I. Afolabi Artificial Intelligence Expert & Software Engineer. Email: javafolabi@gmail.com | victor.afolabi@zephyrtel.com GitHub: https://github.com/victor-iyiola

@project

File: consts.py Created on 20 December, 2018 @ 07:03 PM.

@license

MIT License Copyright (c) 2018. Victor I. Afolabi. All rights reserved.

class adversarials.core.consts.FS

Bases: object

APP_NAME = 'Simple_GAN'
ASSET_DIR = '/home/travis/build/deven96/Simple_GAN/assets'
CACHE_DIR = '/home/travis/build/deven96/Simple_GAN/assets/cache'
LOG_DIR = '/home/travis/build/deven96/Simple_GAN/assets/cache/logs'
MODEL_DIR = '/home/travis/build/deven96/Simple_GAN/assets/cache/models'
PROJECT_DIR = '/home/travis/build/deven96/Simple_GAN'
class adversarials.core.consts.SETUP

Bases: object

MODE = 'Debug'
class adversarials.core.consts.LOGGER

Bases: object

ROOT = '/home/travis/build/deven96/Simple_GAN/adversarials/config/logger/Debug.cfg'

adversarials.core.utils module

Utility file for Adversarial package.

@author

Victor I. Afolabi Artificial Intelligence Expert & Software Engineer. Email: javafolabi@gmail.com | victor.afolabi@zephyrtel.com GitHub: https://github.com/victor-iyiola

@project

File: utils.py Created on 20 December, 2018 @ 07:00 PM.

@license

MIT License Copyright (c) 2018. Victor I. Afolabi. All rights reserved.

class adversarials.core.utils.File

Bases: object

static get_dirs(path: str, exclude: Iterable[str] = None, optimize: bool = False)

Retrieve all directories in a given path.

Args:

path (str): Base directory of directories to retrieve. exclude (Iterable[str], optional): Defaults to None. List of paths to

remove from results.

optimize (bool, optional): Defaults to False. Return an generator object,

to prevent loading all directories in memory, otherwise: return results as a normal list.

Raises:

FileNotFoundError: path was not found.

Returns:
Union[Generator[str], List[str]]: Generator expression if optimization is turned on,

otherwise list of directories in given path.

static get_files(path: str, exclude: Iterable[str] = None, optimize: bool = False)

Retrieve all files in a given path.

Args:

path (str): Base directory of files to retrieve. exclude (Iterable[str], optional): Defaults to None. List of paths to

remove from results.

optimize (bool, optional): Defaults to False. Return an generator object,

to prevent loading all directories in memory, otherwise: return results as a normal list.

Raises:

FileNotFoundError: path was not found.

Returns:
Union[Generator[str], List[str]]: Generator expression if optimization is turned on,

otherwise list of files in given path.

static listdir(path: str, exclude: Iterable[str] = None, dirs_only: bool = False, files_only: bool = False, optimize: bool = False)

Retrieve files/directories in a given path.

Args:

path (str): Base directory of path to retrieve. exclude (Iterable[str], optional): Defaults to None. List of paths to

remove from results.

dirs_only (bool, optional): Defaults to False. Return only directories in path. files_only (bool, optional): Defaults to False. Return only files in path. optimize (bool, optional): Defaults to False. Return an generator object,

to prevent loading all directories in memory, otherwise: return results as a normal list.

Raises:

FileNotFoundError: path was not found.

Returns:
Union[Generator[str], List[str]]: Generator expression if optimization is turned on,

otherwise list of directories in given path.

static make_dirs(path: str, verbose: int = 0)

Create Directory if it doesn’t exist.

Args:

path (str): Directory/directories to be created. verbose (bool, optional): Defaults to 0. 0 turns of logging,

while 1 gives feedback on creation of director(y|ies).

Example:

`python >>> path = os.path.join("path/to", "be/created/") >>> File.make_dirs(path, verbose=1) INFO  |  "path/to/be/created/" has been created. `

class adversarials.core.utils.Log

Bases: object

static critical(*args, **kwargs)
static debug(*args, **kwargs)
static error(*args, **kwargs)
static info(*args, **kwargs)
level = 10
static log(*args, **kwargs)

Logging method avatar based on verbosity.

Args:

*args

Keyword Args:

verbose (int, optional): Defaults to 1. level (int, optional): Defaults to Log.level. sep (str, optional): Defaults to ” “.

Returns:

None

static progress(count: int, max_count: int)

Prints task progress (in %).

Args:

count {int}: Current progress so far. max_count {int}: Total progress length.

static report_hook(block_no: int, read_size: bytes, file_size: bytes)

Calculates download progress given the block number, read size, and the total file size of the URL target.

Args:

block_no {int}: Current download state. read_size {bytes}: Current downloaded size. file_size {bytes}: Total file size.

Returns:

None.

static setLevel(level: int)
static warn(*args, **kwargs)

Module contents

Adversarial core package.

@author

Victor I. Afolabi Artificial Intelligence Expert & Software Engineer. Email: javafolabi@gmail.com | victor.afolabi@zephyrtel.com GitHub: https://github.com/victor-iyiola

@project

File: __init__.py Created on 20 December, 2018 @ 06:56 PM.

@license

MIT License Copyright (c) 2018. Victor I. Afolabi. All rights reserved.

class adversarials.core.SimpleGAN(size: Union[Tuple[int], int] = 28, channels: int = 1, batch_size: int = 32, **kwargs)

Bases: adversarials.core.base.ModelBase

Simple Generative Adversarial Network.

Methods:

def __init__(self, size: Union[Tuple[int], int]=28, channels: int=1, batch_size: int=32, **kwargs)

def train(self, X_train, epochs: int=10):

def plot_images(self, samples: int=16, step:int=0):

# Plot generated images

Attributes:

G (keras.model.Model): Generator model. D (keras.model.Model): Discriminator model. model (keras.model.Model): Combined G & D model. shape (Tuple[int]): Input image shape.

call(n: int = 1, dim: int = 100)

Inference method. Given a random latent sample. Generate an image.

Args:
samples (int, optional): Defaults to 1. Number of images to

be generated.

dim (int, optional): Defaults to 100. Noise dimension.

Returns:

np.ndarray: Array-like generated images.

property model

Stacked generator-discriminator model.

Returns:

keras.model.Model: Combined G & D model.

plot_images(samples=16, step=0)

Plot and generate images

samples (int, optional): Defaults to 16. Noise samples to generate. step (int, optional): Defaults to 0. Number of training step currently.

property shape

Input image shape.

Returns:

Tuple[int]: image shape.

train(X_train, epochs: int = 10)

Train function to be used after GAN initialization

X_train[np.array]: full set of images to be used

class adversarials.core.Log

Bases: object

static critical(*args, **kwargs)
static debug(*args, **kwargs)
static error(*args, **kwargs)
static info(*args, **kwargs)
level = 10
static log(*args, **kwargs)

Logging method avatar based on verbosity.

Args:

*args

Keyword Args:

verbose (int, optional): Defaults to 1. level (int, optional): Defaults to Log.level. sep (str, optional): Defaults to ” “.

Returns:

None

static progress(count: int, max_count: int)

Prints task progress (in %).

Args:

count {int}: Current progress so far. max_count {int}: Total progress length.

static report_hook(block_no: int, read_size: bytes, file_size: bytes)

Calculates download progress given the block number, read size, and the total file size of the URL target.

Args:

block_no {int}: Current download state. read_size {bytes}: Current downloaded size. file_size {bytes}: Total file size.

Returns:

None.

static setLevel(level: int)
static warn(*args, **kwargs)
class adversarials.core.File

Bases: object

static get_dirs(path: str, exclude: Iterable[str] = None, optimize: bool = False)

Retrieve all directories in a given path.

Args:

path (str): Base directory of directories to retrieve. exclude (Iterable[str], optional): Defaults to None. List of paths to

remove from results.

optimize (bool, optional): Defaults to False. Return an generator object,

to prevent loading all directories in memory, otherwise: return results as a normal list.

Raises:

FileNotFoundError: path was not found.

Returns:
Union[Generator[str], List[str]]: Generator expression if optimization is turned on,

otherwise list of directories in given path.

static get_files(path: str, exclude: Iterable[str] = None, optimize: bool = False)

Retrieve all files in a given path.

Args:

path (str): Base directory of files to retrieve. exclude (Iterable[str], optional): Defaults to None. List of paths to

remove from results.

optimize (bool, optional): Defaults to False. Return an generator object,

to prevent loading all directories in memory, otherwise: return results as a normal list.

Raises:

FileNotFoundError: path was not found.

Returns:
Union[Generator[str], List[str]]: Generator expression if optimization is turned on,

otherwise list of files in given path.

static listdir(path: str, exclude: Iterable[str] = None, dirs_only: bool = False, files_only: bool = False, optimize: bool = False)

Retrieve files/directories in a given path.

Args:

path (str): Base directory of path to retrieve. exclude (Iterable[str], optional): Defaults to None. List of paths to

remove from results.

dirs_only (bool, optional): Defaults to False. Return only directories in path. files_only (bool, optional): Defaults to False. Return only files in path. optimize (bool, optional): Defaults to False. Return an generator object,

to prevent loading all directories in memory, otherwise: return results as a normal list.

Raises:

FileNotFoundError: path was not found.

Returns:
Union[Generator[str], List[str]]: Generator expression if optimization is turned on,

otherwise list of directories in given path.

static make_dirs(path: str, verbose: int = 0)

Create Directory if it doesn’t exist.

Args:

path (str): Directory/directories to be created. verbose (bool, optional): Defaults to 0. 0 turns of logging,

while 1 gives feedback on creation of director(y|ies).

Example:

`python >>> path = os.path.join("path/to", "be/created/") >>> File.make_dirs(path, verbose=1) INFO  |  "path/to/be/created/" has been created. `

class adversarials.core.ModelBase(*args, **kwargs)

Bases: adversarials.core.base._Base

property cache_dir
abstract call(*args, **kwargs)
static int_shape(x)

Returns the shape of tensor or variable as tuple of int or None entries.

Args:

x (Union[tf.Tensor, tf.Variable]): Tensor or variable. hasattr(x, ‘shape’)

Returns:

tuple: A tuple of integers (or None entries).

class adversarials.core.Config

Bases: object

static from_cfg(file: str, ext: str = 'cfg')

Load configuration from an cfg file.

Args:

file (str): An cfg filename. ext (str, optional): Defaults to ‘cfg’. Config file extension.

Raises:

AssertionError: File is not an ${ext} file. FileNotFoundError: file was not found.

Returns:

easydict.EasyDict: config dictionary object.

static from_json(file: str)

Load configuration from a json file.

Args:

file (str): A JSON filename.

Raises:

AssertionError: File is not a JSON file. FileNotFoundError: file was not found.

Returns:

easydict.EasyDict: config dictionary object.

static from_yaml(file: str)

Load configuration from a YAML file.

Args:

file (str): A .yml or .yaml filename.

Raises:

AssertionError: File is not a YAML file. FileNotFoundError: file was not found.

Returns:

easydict.EasyDict: config dictionary object.

static to_cfg(cfg: easydict.EasyDict, file: str, **kwargs)

Save configuration object into a cfg or ini file.

Args:

cfg (Any): Configuration: as dictionary instance. file (str): Path to write the configuration to.

Keyword Args:

Passed into dumper.

static to_json(cfg: easydict.EasyDict, file: str, **kwargs)

Save configuration object into a JSON file.

Args:

cfg (EasyDict): Configuration: as dictionary instance. file (str): Path to write the configuration to.

Keyword Args:

Passed into dumper.

Raises:

AssertionError: dumper must be callable.

static to_pickle(cfg: Any, file: str, **kwargs)

Save configuration object into a pickle file.

Args:

cfg (Any): Configuration: as dictionary instance. file (str): Path to write the configuration to.

Keyword Args:

Passed into dumper.

Raises:

AssertionError: dumper must be callable.

static to_yaml(cfg: easydict.EasyDict, file: str, **kwargs)

Save configuration object into a YAML file.

Args:

cfg (EasyDict): Configuration: as a dictionary instance. file (str): Path to write the configuration to.

Keyword Args:

Passed into dumper.

Raises:

AssertionError: dumper must be callable.

class adversarials.core.FS

Bases: object

APP_NAME = 'Simple_GAN'
ASSET_DIR = '/home/travis/build/deven96/Simple_GAN/assets'
CACHE_DIR = '/home/travis/build/deven96/Simple_GAN/assets/cache'
LOG_DIR = '/home/travis/build/deven96/Simple_GAN/assets/cache/logs'
MODEL_DIR = '/home/travis/build/deven96/Simple_GAN/assets/cache/models'
PROJECT_DIR = '/home/travis/build/deven96/Simple_GAN'
class adversarials.core.LOGGER

Bases: object

ROOT = '/home/travis/build/deven96/Simple_GAN/adversarials/config/logger/Debug.cfg'
class adversarials.core.SETUP

Bases: object

MODE = 'Debug'