Skip to content
Snippets Groups Projects
Commit e2deb70d authored by Amir MOHAMMADI's avatar Amir MOHAMMADI
Browse files

Fix the documentation

parent 5ba976b8
No related branches found
No related tags found
1 merge request!68Several changes
Pipeline #24654 failed
...@@ -30,13 +30,13 @@ class BioGenerator(object): ...@@ -30,13 +30,13 @@ class BioGenerator(object):
``data = load_data(database, biofile)``. ``data = load_data(database, biofile)``.
:any:`bob.bio.base.read_original_data` is wrapped to be used by :any:`bob.bio.base.read_original_data` is wrapped to be used by
default. default.
multiple_samples : bool, optional multiple_samples : :obj:`bool`, optional
If true, it assumes that the bio database's samples actually contain If true, it assumes that the bio database's samples actually contain
multiple samples. This is useful for when you want to for example treat multiple samples. This is useful for when you want to for example treat
video databases as image databases. video databases as image databases.
output_types : (object, object, object) output_types : (object, object, object)
The types of the returned samples. The types of the returned samples.
output_shapes : (tf.TensorShape, tf.TensorShape, tf.TensorShape) output_shapes : ``(tf.TensorShape, tf.TensorShape, tf.TensorShape)``
The shapes of the returned samples. The shapes of the returned samples.
""" """
......
""" """
The network using keras (same as new_architecture function below): The network using keras (same as new_architecture function below)::
```
from tensorflow.python.keras import * from tensorflow.python.keras import *
from tensorflow.python.keras.layers import * from tensorflow.python.keras.layers import *
simplecnn = Sequential([ simplecnn = Sequential([
Conv2D(32,(3,3),padding='same',use_bias=False, input_shape=(28,28,3)), Conv2D(32,(3,3),padding='same',use_bias=False, input_shape=(28,28,3)),
BatchNormalization(scale=False), BatchNormalization(scale=False),
Activation('relu'), Activation('relu'),
MaxPool2D(padding='same'), MaxPool2D(padding='same'),
Conv2D(64,(3,3),padding='same',use_bias=False), Conv2D(64,(3,3),padding='same',use_bias=False),
BatchNormalization(scale=False), BatchNormalization(scale=False),
Activation('relu'), Activation('relu'),
MaxPool2D(padding='same'), MaxPool2D(padding='same'),
Flatten(), Flatten(),
Dense(1024, use_bias=False), Dense(1024, use_bias=False),
BatchNormalization(scale=False), BatchNormalization(scale=False),
Activation('relu'), Activation('relu'),
Dropout(rate=0.4), Dropout(rate=0.4),
Dense(2), Dense(2),
]) ])
simplecnn.summary() simplecnn.summary()
``` _________________________________________________________________
_________________________________________________________________ Layer (type) Output Shape Param #
Layer (type) Output Shape Param # =================================================================
================================================================= conv2d_1 (Conv2D) (None, 28, 28, 32) 864
conv2d_1 (Conv2D) (None, 28, 28, 32) 864 _________________________________________________________________
_________________________________________________________________ batch_normalization_1 (Batch (None, 28, 28, 32) 96
batch_normalization_1 (Batch (None, 28, 28, 32) 96 _________________________________________________________________
_________________________________________________________________ activation_1 (Activation) (None, 28, 28, 32) 0
activation_1 (Activation) (None, 28, 28, 32) 0 _________________________________________________________________
_________________________________________________________________ max_pooling2d_1 (MaxPooling2 (None, 14, 14, 32) 0
max_pooling2d_1 (MaxPooling2 (None, 14, 14, 32) 0 _________________________________________________________________
_________________________________________________________________ conv2d_2 (Conv2D) (None, 14, 14, 64) 18432
conv2d_2 (Conv2D) (None, 14, 14, 64) 18432 _________________________________________________________________
_________________________________________________________________ batch_normalization_2 (Batch (None, 14, 14, 64) 192
batch_normalization_2 (Batch (None, 14, 14, 64) 192 _________________________________________________________________
_________________________________________________________________ activation_2 (Activation) (None, 14, 14, 64) 0
activation_2 (Activation) (None, 14, 14, 64) 0 _________________________________________________________________
_________________________________________________________________ max_pooling2d_2 (MaxPooling2 (None, 7, 7, 64) 0
max_pooling2d_2 (MaxPooling2 (None, 7, 7, 64) 0 _________________________________________________________________
_________________________________________________________________ flatten_1 (Flatten) (None, 3136) 0
flatten_1 (Flatten) (None, 3136) 0 _________________________________________________________________
_________________________________________________________________ dense_1 (Dense) (None, 1024) 3211264
dense_1 (Dense) (None, 1024) 3211264 _________________________________________________________________
_________________________________________________________________ batch_normalization_3 (Batch (None, 1024) 3072
batch_normalization_3 (Batch (None, 1024) 3072 _________________________________________________________________
_________________________________________________________________ activation_3 (Activation) (None, 1024) 0
activation_3 (Activation) (None, 1024) 0 _________________________________________________________________
_________________________________________________________________ dropout_1 (Dropout) (None, 1024) 0
dropout_1 (Dropout) (None, 1024) 0 _________________________________________________________________
_________________________________________________________________ dense_2 (Dense) (None, 2) 2050
dense_2 (Dense) (None, 2) 2050 =================================================================
================================================================= Total params: 3,235,970
Total params: 3,235,970 Trainable params: 3,233,730
Trainable params: 3,233,730 Non-trainable params: 2,240
Non-trainable params: 2,240 _________________________________________________________________
_________________________________________________________________
""" """
......
...@@ -21,7 +21,7 @@ def compute_features(input_image, architecture, checkpoint_dir, target_end_point ...@@ -21,7 +21,7 @@ def compute_features(input_image, architecture, checkpoint_dir, target_end_point
Parameters Parameters
---------- ----------
input_image: numpy.array input_image: :any:`numpy.array`
Input image in the format WxHxC Input image in the format WxHxC
architecture: architecture:
...@@ -77,7 +77,7 @@ def compute_gram(features): ...@@ -77,7 +77,7 @@ def compute_gram(features):
Parameters Parameters
---------- ----------
features: numpy.array features: :any:`numpy.array`
Convolved features in the format NxWxHxC Convolved features in the format NxWxHxC
""" """
...@@ -90,7 +90,7 @@ def compute_gram(features): ...@@ -90,7 +90,7 @@ def compute_gram(features):
return grams return grams
def do_style_transfer(content_image, style_images, def do_style_transfer(content_image, style_images,
architecture, checkpoint_dir, scopes, architecture, checkpoint_dir, scopes,
content_end_points, style_end_points, content_end_points, style_end_points,
preprocess_fn=None, un_preprocess_fn=None, pure_noise=False, preprocess_fn=None, un_preprocess_fn=None, pure_noise=False,
...@@ -105,7 +105,7 @@ def do_style_transfer(content_image, style_images, ...@@ -105,7 +105,7 @@ def do_style_transfer(content_image, style_images,
Parameters Parameters
---------- ----------
content_image: numpy.array content_image: :any:`numpy.array`
Content image in the Bob format (C x W x H) Content image in the Bob format (C x W x H)
style_images: :any:`list` style_images: :any:`list`
...@@ -128,7 +128,7 @@ def do_style_transfer(content_image, style_images, ...@@ -128,7 +128,7 @@ def do_style_transfer(content_image, style_images,
preprocess_fn: preprocess_fn:
Preprocess function. Pointer to a function that preprocess the INPUT signal Preprocess function. Pointer to a function that preprocess the INPUT signal
unpreprocess_fn: unpreprocess_fn:
Un preprocess function. Pointer to a function that preprocess the OUTPUT signal Un preprocess function. Pointer to a function that preprocess the OUTPUT signal
...@@ -138,7 +138,7 @@ def do_style_transfer(content_image, style_images, ...@@ -138,7 +138,7 @@ def do_style_transfer(content_image, style_images,
iterations: iterations:
Number of iterations to generate the image Number of iterations to generate the image
learning_rate: learning_rate:
Adam learning rate Adam learning rate
...@@ -147,7 +147,7 @@ def do_style_transfer(content_image, style_images, ...@@ -147,7 +147,7 @@ def do_style_transfer(content_image, style_images,
style_weight: style_weight:
Weight of the style loss Weight of the style loss
denoise_weight: denoise_weight:
Weight denoising loss Weight denoising loss
""" """
...@@ -178,10 +178,10 @@ def do_style_transfer(content_image, style_images, ...@@ -178,10 +178,10 @@ def do_style_transfer(content_image, style_images,
content_end_points, preprocess_fn) content_end_points, preprocess_fn)
# Base style features # Base style features
logger.info("Computing style features") logger.info("Computing style features")
style_grams = [] style_grams = []
for image in style_images: for image in style_images:
style_features = compute_features(image, architecture, checkpoint_dir, style_features = compute_features(image, architecture, checkpoint_dir,
style_end_points, preprocess_fn) style_end_points, preprocess_fn)
style_grams.append(compute_gram(style_features)) style_grams.append(compute_gram(style_features))
...@@ -206,7 +206,7 @@ def do_style_transfer(content_image, style_images, ...@@ -206,7 +206,7 @@ def do_style_transfer(content_image, style_images,
# Computing style_loss # Computing style_loss
style_gram_noises = [] style_gram_noises = []
s_loss = 0 s_loss = 0
for grams_per_image in style_grams: for grams_per_image in style_grams:
for c in style_end_points: for c in style_end_points:
...@@ -227,7 +227,7 @@ def do_style_transfer(content_image, style_images, ...@@ -227,7 +227,7 @@ def do_style_transfer(content_image, style_images,
tf.contrib.framework.init_from_checkpoint(tf.train.latest_checkpoint(checkpoint_dir) if os.path.isdir(checkpoint_dir) else checkpoint_dir, scopes) tf.contrib.framework.init_from_checkpoint(tf.train.latest_checkpoint(checkpoint_dir) if os.path.isdir(checkpoint_dir) else checkpoint_dir, scopes)
# Training # Training
with tf.Session() as sess: with tf.Session() as sess:
sess.run(tf.global_variables_initializer()) sess.run(tf.global_variables_initializer())
for i in range(iterations): for i in range(iterations):
...@@ -258,7 +258,7 @@ def do_style_transfer(content_image, style_images, ...@@ -258,7 +258,7 @@ def do_style_transfer(content_image, style_images,
else: else:
normalized_style_image_yuv = bob.ip.color.rgb_to_yuv(bob.ip.color.gray_to_rgb(bob.ip.color.rgb_to_gray(normalized_style_image))) normalized_style_image_yuv = bob.ip.color.rgb_to_yuv(bob.ip.color.gray_to_rgb(bob.ip.color.rgb_to_gray(normalized_style_image)))
content_image_yuv = bob.ip.color.rgb_to_yuv(bob.io.base.load(content_image_path)) content_image_yuv = bob.ip.color.rgb_to_yuv(bob.io.base.load(content_image_path))
output_image = numpy.zeros(shape=content_image_yuv.shape, dtype="uint8") output_image = numpy.zeros(shape=content_image_yuv.shape, dtype="uint8")
output_image[0,:,:] = normalized_style_image_yuv[0,:,:] output_image[0,:,:] = normalized_style_image_yuv[0,:,:]
output_image[1,:,:] = content_image_yuv[1,:,:] output_image[1,:,:] = content_image_yuv[1,:,:]
......
...@@ -40,6 +40,7 @@ requirements: ...@@ -40,6 +40,7 @@ requirements:
run: run:
- python - python
- setuptools - setuptools
- numpy
- scipy - scipy
- six - six
- tensorflow >=1.4 - tensorflow >=1.4
......
...@@ -31,7 +31,7 @@ Architectures ...@@ -31,7 +31,7 @@ Architectures
bob.learn.tensorflow.network.inception_resnet_v1 bob.learn.tensorflow.network.inception_resnet_v1
bob.learn.tensorflow.network.inception_resnet_v2_batch_norm bob.learn.tensorflow.network.inception_resnet_v2_batch_norm
bob.learn.tensorflow.network.inception_resnet_v1_batch_norm bob.learn.tensorflow.network.inception_resnet_v1_batch_norm
bob.learn.tensorflow.network.SimpleCNN.base_architecture bob.learn.tensorflow.network.SimpleCNN.slim_architecture
bob.learn.tensorflow.network.vgg_19 bob.learn.tensorflow.network.vgg_19
bob.learn.tensorflow.network.vgg_16 bob.learn.tensorflow.network.vgg_16
......
...@@ -17,4 +17,5 @@ bob.db.mnist ...@@ -17,4 +17,5 @@ bob.db.mnist
bob.db.atnt bob.db.atnt
gridtk gridtk
bob.bio.base bob.bio.base
numpy
scipy scipy
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment