Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Raphael Zumer
aom-rav1e
Commits
39a33e5c
Commit
39a33e5c
authored
Jul 04, 2018
by
Raphael Zumer
Browse files
Add libaom ML framework
parent
8ac57e6b
Changes
2
Hide whitespace changes
Inline
Side-by-side
av1/encoder/ml.c
0 → 100644
View file @
39a33e5c
/*
* Copyright (c) 2016, Alliance for Open Media. All rights reserved
*
* This source code is subject to the terms of the BSD 2 Clause License and
* the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
* was not distributed with this source code in the LICENSE file, you can
* obtain it at www.aomedia.org/license/software. If the Alliance for Open
* Media Patent License 1.0 was not distributed with this source code in the
* PATENTS file, you can obtain it at www.aomedia.org/license/patent.
*/
#include <assert.h>
#include "av1/encoder/ml.h"
void
av1_nn_predict
(
const
float
*
features
,
const
NN_CONFIG
*
nn_config
,
float
*
output
)
{
int
num_input_nodes
=
nn_config
->
num_inputs
;
int
buf_index
=
0
;
float
buf
[
2
][
NN_MAX_NODES_PER_LAYER
];
const
float
*
input_nodes
=
features
;
// Propagate hidden layers.
const
int
num_layers
=
nn_config
->
num_hidden_layers
;
assert
(
num_layers
<=
NN_MAX_HIDDEN_LAYERS
);
for
(
int
layer
=
0
;
layer
<
num_layers
;
++
layer
)
{
const
float
*
weights
=
nn_config
->
weights
[
layer
];
const
float
*
bias
=
nn_config
->
bias
[
layer
];
float
*
output_nodes
=
buf
[
buf_index
];
const
int
num_output_nodes
=
nn_config
->
num_hidden_nodes
[
layer
];
assert
(
num_output_nodes
<
NN_MAX_NODES_PER_LAYER
);
for
(
int
node
=
0
;
node
<
num_output_nodes
;
++
node
)
{
float
val
=
0
.
0
f
;
for
(
int
i
=
0
;
i
<
num_input_nodes
;
++
i
)
val
+=
weights
[
i
]
*
input_nodes
[
i
];
val
+=
bias
[
node
];
// ReLU as activation function.
val
=
val
>
0
.
0
f
?
val
:
0
.
0
f
;
// Could use AOMMAX().
output_nodes
[
node
]
=
val
;
weights
+=
num_input_nodes
;
}
num_input_nodes
=
num_output_nodes
;
input_nodes
=
output_nodes
;
buf_index
=
1
-
buf_index
;
}
// Final output layer.
const
float
*
weights
=
nn_config
->
weights
[
num_layers
];
for
(
int
node
=
0
;
node
<
nn_config
->
num_outputs
;
++
node
)
{
const
float
*
bias
=
nn_config
->
bias
[
num_layers
];
float
val
=
0
.
0
f
;
for
(
int
i
=
0
;
i
<
num_input_nodes
;
++
i
)
val
+=
weights
[
i
]
*
input_nodes
[
i
];
output
[
node
]
=
val
+
bias
[
node
];
weights
+=
num_input_nodes
;
}
}
av1/encoder/ml.h
0 → 100644
View file @
39a33e5c
/*
* Copyright (c) 2016, Alliance for Open Media. All rights reserved
*
* This source code is subject to the terms of the BSD 2 Clause License and
* the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
* was not distributed with this source code in the LICENSE file, you can
* obtain it at www.aomedia.org/license/software. If the Alliance for Open
* Media Patent License 1.0 was not distributed with this source code in the
* PATENTS file, you can obtain it at www.aomedia.org/license/patent.
*/
#ifndef AV1_ENCODER_ML_H_
#define AV1_ENCODER_ML_H_
#ifdef __cplusplus
extern
"C"
{
#endif
#define NN_MAX_HIDDEN_LAYERS 10
#define NN_MAX_NODES_PER_LAYER 128
typedef
struct
{
int
num_inputs
;
// Number of input nodes, i.e. features.
int
num_outputs
;
// Number of output nodes.
int
num_hidden_layers
;
// Number of hidden layers, maximum 10.
// Number of nodes for each hidden layer.
int
num_hidden_nodes
[
NN_MAX_HIDDEN_LAYERS
];
// Weight parameters, indexed by layer.
const
float
*
weights
[
NN_MAX_HIDDEN_LAYERS
+
1
];
// Bias parameters, indexed by layer.
const
float
*
bias
[
NN_MAX_HIDDEN_LAYERS
+
1
];
}
NN_CONFIG
;
// Calculate prediction based on the given input features and neural net config.
// Assume there are no more than NN_MAX_NODES_PER_LAYER nodes in each hidden
// layer.
void
av1_nn_predict
(
const
float
*
features
,
const
NN_CONFIG
*
nn_config
,
float
*
output
);
#ifdef __cplusplus
}
// extern "C"
#endif
#endif // AV1_ENCODER_RD_H_
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment