Skip to content
Open

Pcs #41

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ It can also be used with a python environment in the following manner:
from keras2c import k2c
k2c(model, function_name, malloc=False, num_tests=10, verbose=True)

For more information, see `Installation <https://f0uriest.github.io/keras2c/installation.html>`_ and `Usage <https://f0uriest.github.io/keras2c/usage.html>`_
For more information, see `Installation <https://plasmacontrol.github.io/keras2c/installation.html>`_ and `Usage <https://plasmacontrol.github.io/keras2c/usage.html>`_


Supported Layers
Expand Down Expand Up @@ -73,24 +73,24 @@ ToDo
Contribute
**********

- Documentation: `<https://f0uriest.github.io/keras2c/>`_
- Issue Tracker: `<https://github.com/f0uriest/keras2c/issues>`_
- Source Code: `<https://github.com/f0uriest/keras2c/>`_
- Documentation: `<https://plasmacontrol.github.io/keras2c/>`_
- Issue Tracker: `<https://github.com/plasmacontrol/keras2c/issues>`_
- Source Code: `<https://github.com/plasmacontrol/keras2c/>`_

License
*******

The project is licensed under the LGPLv3 license.


.. |Build-Status| image:: https://travis-ci.org/f0uriest/keras2c.svg?branch=master
:target: https://travis-ci.org/f0uriest/keras2c
.. |Build-Status| image:: https://travis-ci.org/plasmacontrol/keras2c.svg?branch=master
:target: https://travis-ci.org/plasmacontrol/keras2c
:alt: Build Status
.. |Codecov| image:: https://codecov.io/gh/f0uriest/keras2c/branch/master/graph/badge.svg
:target: https://codecov.io/gh/f0uriest/keras2c
.. |Codecov| image:: https://codecov.io/gh/plasmacontrol/keras2c/branch/master/graph/badge.svg
:target: https://codecov.io/gh/plasmacontrol/keras2c
:alt: Code Coverage
.. |License| image:: https://img.shields.io/github/license/f0uriest/keras2c
:target: https://github.com/f0uriest/keras2c/blob/master/LICENSE
.. |License| image:: https://img.shields.io/github/license/plasmacontrol/keras2c
:target: https://github.com/plasmacontrol/keras2c/blob/master/LICENSE
:alt: License: LGPLv3
.. |DOI| image:: https://zenodo.org/badge/193152058.svg
:target: https://zenodo.org/badge/latestdoi/193152058
Expand Down
18 changes: 18 additions & 0 deletions include/k2c_activations.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,24 @@ void k2c_sigmoid_func(float * x, const size_t size) {
}
k2c_activationType * k2c_sigmoid = k2c_sigmoid_func;

/**
* swish activation function.
* y = x * (1/(1+exp(-x)))
*
* :param x: array of input values. Gets overwritten by output.
* :param size: length of input array.
*/
void k2c_swish_func(float * x, const size_t size) {

for (size_t i = 0; i < size; ++i) {
float xv = x[i];
float v = xv;
if (v < -30.0f) v = -30.0f; // Clamp to avoid overflow
x[i] = xv / (1.0f + expf(-v));
}
}
k2c_activationType * k2c_swish = k2c_swish_func;


/**
* Soft max activation function.
Expand Down
73 changes: 73 additions & 0 deletions include/k2c_conv_transpose_layer.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#include <string.h>
#include "k2c_include.h"

/**
* 1D (temporal) Convolution.
* Assumes a "channels last" structure.
*
* :param output: output tensor.
* :param input: input tensor.
* :param kernel: kernel tensor.
* :param bias: bias tensor.
* :param stride: stride length of the convolution.
* :param dilation: dilation rate to use for dilated convolution.
* :param activation: activation function to apply to output.
*/
void k2c_conv1d_transpose(k2c_tensor *output, const k2c_tensor *input,
const k2c_tensor *kernel, const k2c_tensor *bias,
const size_t stride, const size_t start_crop,
k2c_activationType *activation)
{
memset(output->array, 0, output->numel * sizeof(output->array[0]));

const size_t n_height = input->shape[0];
const size_t n_channels = input->shape[1];
const size_t k_size = kernel->shape[0];
const size_t n_filters = kernel->shape[1];
const size_t out_height = output->shape[0];

const size_t ker_dim12 = n_channels * n_filters;

size_t cs = 0;
size_t ce = 0;
size_t ts = 0;
size_t ks = 0;

for (size_t f = 0; f < n_filters; ++f)
{
for (size_t ch = 0; ch < n_channels; ++ch)
{
for (size_t t = 0; t < n_height; ++t)
{
ts = t * stride;
if (ts > start_crop)
{
cs = ts - start_crop;
}
else
{
cs = 0;
}
if (ts + k_size - start_crop > out_height)
{
ce = out_height;
}
else
{
ce = ts + k_size - start_crop;
}
ks = cs - (ts - start_crop);
for (size_t i = 0; i < ce - cs; ++i)
{
output->array[(i + cs) * n_filters + f] +=
kernel->array[(i + ks) * ker_dim12 + f * n_channels + ch] *
input->array[t * n_channels + ch];
}
}
}
}
// }

k2c_bias_add(output, bias);
activation(output->array, output->numel);
}
Loading