Ejemplo n.º 1
0
# Next, we load the stimulus. Opening the image files can be expensive
# so we're doing at this at the very start and loading them into a
# variable.

# `IMAGE_TEMPLATE` is a string of the filepath of the stimulus digit images.
config.IMAGE_TEMPLATE = './images/{}.png'

# `IMAGE_SIZE` is an (int, int) tuple of the image size of the first image.
# We assume that each image is of the same size as the image labelled "0"
config.IMAGE_SIZE = np.shape(imread(config.IMAGE_TEMPLATE.format(0)))

# `IMAGES` holds the original digit images.
config.IMAGES = [
    cv2.cvtColor(
        cv2.resize(imread(config.IMAGE_TEMPLATE.format(digit)),
                   dsize=(TRAINING_CONFIG.grid.render_shape)),
        cv2.COLOR_RGBA2RGB) for digit in range(10)
]

# Initialise the checkpoint
if config.CONDITION == 0:
    config.PROCESSOR = Stimulus
else:
    LEARNING_RATE_ENCODER = TRAINING_CONFIG.learning_rate_encoder
    LEARNING_RATE_DECODER = TRAINING_CONFIG.learning_rate_decoder
    ENCODER_OPTIMISER = tf.keras.optimizers.Adam(
        learning_rate=LEARNING_RATE_ENCODER)
    DECODER_OPTIMISER = tf.keras.optimizers.Adam(
        learning_rate=LEARNING_RATE_DECODER)

    CHECKPOINT = tf.train.Checkpoint(
Ejemplo n.º 2
0
# `IMAGE_TEMPLATE` is a string of the filepath of the stimulus digit images.
config.IMAGE_TEMPLATE = './data/digit-images-aliased/{}.png'

# `IMAGE_SIZE` is an (int, int) tuple of the image size of the first image.
# We assume that each image is of the same size as the image labelled "0"
config.IMAGE_SIZE = np.shape(imread(config.IMAGE_TEMPLATE.format(0)))

# `IMAGE_SCALE` is an int describing the ratio of electrode size to image size.
# It assumes that EXSIZE == EYSIZE and the input images are square.
# This may need changing later.
config.IMAGE_SCALE = config.EXSIZE / config.IMAGE_SIZE[0]

# `IMAGES` holds the original digit images.
config.IMAGES = [
    cv2.cvtColor(
        cv2.resize(imread(config.IMAGE_TEMPLATE.format(digit)),
                   dsize=(config.INPUT_XSIZE, config.INPUT_YSIZE)),
        cv2.COLOR_RGBA2RGB) for digit in range(10)
]

# `STIMULI` contains a list of numpy arrays.
# Each element in the list holds the image data
# for the digit equal to its index. Normalised to
# between -1 and 1
config.STIMULI = [
    np.array(Image.fromarray(image).resize((config.EXSIZE, config.EYSIZE)))
    for image in config.IMAGES
]

# We initiate a grid of electrodes.
grids = {
    'cartesian':