<commit_before># Spatial Transformer Network with Affine and Thin Plate Spline Transformations

The Spatial Transformer Network [1] allows the spatial manipulation of data within the network.

<div align="center">
  <img width="600px" src="http://i.imgur.com/ExGDVul.png"><br><br>
</div>

A Spatial Transformer Network implemented in Tensorflow 0.9 and based on [2] \(which is also in [3]\), and [4].

This tensorflow implementation supports Affine Transformations and Thin Plate Spline Deformations [5].


<div align="center">
  <img src="http://i.imgur.com/gfqLV3f.png"><br><br>
</div>

## How to use

### Create Layer

```python
from stn import AffineTransformer
out_size = [300, 300]
stl1 = AffineTransformer(out_size)
```

```python
from stn import TPSTransformer
out_size = [300, 300]
num_control_points = 16 
stl2 = TPSTransformer(out_size, num_control_points)
```

#### Parameters
    U : float 
        The output of a convolutional net should have the
        shape [num_batch, height, width, num_channels]. 
    out_size : tuple of two ints
        The size of the output of the network
    num_control_points : int
        The number of control points that define 
        Thin Plate Splines deformation field. 
        *MUST* be a square of an integer. 
        16 by default.

### Transform Input Tensor

```python
stl1.transform(U, theta)
stl2.transform(U, theta)
```

#### Parameters
##### Affine Transformation
    theta : float   
        The output of the localisation network,
        should have size [num_batch, 6].

To initialize the network to the identity transform init ``theta`` to :
```python
identity = np.array([[1., 0., 0.],
                    [0., 1., 0.]]) 
identity = identity.flatten()
theta = tf.Variable(initial_value=identity)
```        

##### Thin Plate Splines STN
    theta : float   
        The output of the localisation network,
        should have size [num_batch, num_control_points x 2].
        num_control_points must be a square of an integer.
        
To initialize the network to the identity transform init ``theta`` to zeros:
```python
identity = np.zeros(num_control_points,2).astype('float32')
theta = tf.Variable(initial_value=identity)
```        

### References

[1] Jaderberg, Max, et al. "Spatial Transformer Networks." 
    arXiv preprint arXiv:1506.02025 (2015)

[2] https://github.com/skaae/transformer_network/blob/master/transformerlayer.py<commit_msg>readme update<commit_after># Spatial Transformer Network with Affine and Thin Plate Spline Transformations

The Spatial Transformer Network [1] allows the spatial manipulation of data within the network.

<div align="center">
  <img width="600px" src="http://i.imgur.com/ExGDVul.png"><br><br>
</div>

A Spatial Transformer Network implemented in Tensorflow 0.9 and based on [2] \(which is also in [3]\), and [4].

This tensorflow implementation supports Affine Transformations and Thin Plate Spline Deformations [5].


<div align="center">
  <img src="http://i.imgur.com/gfqLV3f.png"><br><br>
</div>

## How to use

### Create Layer

```python
from stn import AffineTransformer
out_size = [300, 300]
stl1 = AffineTransformer(out_size)
```

```python
from stn import TPSTransformer
out_size = [300, 300]
num_control_points = 16 
stl2 = TPSTransformer(out_size, num_control_points)
```

#### Parameters
    out_size : tuple of two ints
        The size of the output of the network
    num_control_points : int
        The number of control points that define 
        Thin Plate Splines deformation field. 
        *MUST* be a square of an integer. 
        16 by default.

### Transform Input Tensor

```python
stl1.transform(U, theta)
stl2.transform(U, theta)
```

#### Parameters

    U : float 
        The output of a convolutional net should have the
        shape [num_batch, height, width, num_channels]. 

##### Affine Transformation
    theta : float   
        The output of the localisation network,
        should have size [num_batch, 6].

To initialize the network to the identity transform init ``theta`` to :
```python
identity = np.array([[1., 0., 0.],
                    [0., 1., 0.]]) 
identity = identity.flatten()
theta = tf.Variable(initial_value=identity)
```        

##### Thin Plate Splines STN
    theta : float   
        The output of the localisation network,
        should have size [num_batch, num_control_points x 2].
        num_control_points must be a square of an integer.
        
To initialize the network to the identity transform init ``theta`` to zeros:
```python
identity = np.zeros(num_control_points,2).astype('float32')
theta = tf.Variable(initial_value=identity)
```        

### References

[1] Jaderberg, Max, et al. "Spatial Transformer Networks." 
    arXiv preprint arXiv:1506.02025 (2015)

[2] https://github.com/skaae/transformer_network/blob/master/transformerlayer.py
{'fraction_non_alphanumeric': 0.10849834983498349, 'fraction_numerical': 0.023514851485148515, 'mean_word_length': 3.4898148148148147, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5667594', 'n_tokens_mistral': 1619, 'n_tokens_neox': 1441, 'n_words': 510}