Skip to content

Commit 16a3b93

Browse files
authored
Merge pull request #212 from sguttikon/master
Copyright + License changes to files in examples folder
2 parents f9a7d12 + 9a148e2 commit 16a3b93

File tree

20 files changed

+1416
-737
lines changed

20 files changed

+1416
-737
lines changed

CITATION.cff

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
cff-version: 1.2.0
2+
message: "If you use this software, please cite it as below."
3+
authors:
4+
- family-names: "Izquierdo"
5+
given-names: "Sergio"
6+
orcid: "https://orcid.org/0000-0002-5639-5035"
7+
title: "cppflow"
8+
version: 1.0.0
9+
doi: 10.5281/zenodo.1234
10+
date-released: 2019-05-16
11+
url: "https://github.com/serizba/cppflow"

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ There you can find quickstart guides and more information about how to install t
5656

5757
## Development
5858

59-
CppFlow is basically a wrapper over Tensorflow C API. The basic class, [tensor](https://github.com/serizba/cppflow/blob/master/include/cppflow/tensor.h) is a wrapper of a TF eager tensor, and it just constains a pointer to its TF representation.
59+
CppFlow is basically a wrapper over Tensorflow C API. The basic class, [tensor](https://github.com/serizba/cppflow/blob/master/include/cppflow/tensor.h) is a wrapper of a TF eager tensor, and it just constains a pointer to its TF representation.
6060

6161
The TF C API provides the tools to call all the TF [raw ops](https://www.tensorflow.org/api_docs/python/tf/raw_ops), but using them is confusing. CppFlow includes a facade over these functions, so they can be called easily as normal C++ functions. To achieve this, the file [ops](https://github.com/serizba/cppflow/blob/master/include/cppflow/raw_ops.h) contains (mostly) all the TF raw ops functions, but with a simple C++ interface. This file has been generated automatically using a [small script](https://github.com/serizba/cppflow/blob/master/include/cppflow/ops_generator/generator.py).
6262

@@ -74,6 +74,10 @@ There are still many things to implement... some of them may be:
7474

7575
You can also use the [older version](https://github.com/serizba/cppflow/tree/243ff2fc4e33632b91676cad7d6cfc3c92308601) of this work.
7676

77+
## Style guide
78+
79+
We use the [Google's C++ style guide](https://google.github.io/styleguide/cppguide.html) using static code linker [cpplint](https://github.com/cpplint/cpplint).
80+
7781
## Remark
7882

79-
CppFlow is not related with TensorFlow. The CppFlow icon is a modified version of the TensorFlow logo. TensorFlow, the TensorFlow logo and any related marks are trademarks of Google Inc.
83+
CppFlow is not related with TensorFlow. The CppFlow icon is a modified version of the TensorFlow logo. TensorFlow, the TensorFlow logo and any related marks are trademarks of Google Inc.

examples/eager_op_multithread/main.cpp

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,64 @@
1+
// MIT License
2+
//
3+
// Copyright (c) 2020 Jiannan Liu
4+
// Copyright (c) 2022 Sergio Izquierdo
5+
//
6+
// Permission is hereby granted, free of charge, to any person obtaining a copy
7+
// of this software and associated documentation files (the "Software"), to deal
8+
// in the Software without restriction, including without limitation the rights
9+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
// copies of the Software, and to permit persons to whom the Software is
11+
// furnished to do so, subject to the following conditions:
12+
//
13+
// The above copyright notice and this permission notice shall be included in
14+
// all copies or substantial portions of the Software.
15+
//
16+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
// SOFTWARE.
23+
24+
/*!
25+
* @file main.cpp
26+
* @brief A brief description here.
27+
* @details Define custom details for the file here.
28+
* @author Jiannan Liu
29+
* @author Sergio Izquierdo
30+
* @date @showdate "%B %d, %Y" 2020-10-26
31+
*/
32+
33+
// CppFlow headers
34+
#include <cppflow/cppflow.h>
35+
36+
// C++ headers
137
#include <thread>
238
#include <cmath>
339
#include <vector>
440
#include <iostream>
541

6-
#include <cppflow/cppflow.h>
7-
842
constexpr size_t num_iter = 10240;
943
constexpr size_t num_threads = 32;
1044

1145
void test1(float input1, float input2, float input3) {
1246
float target = (input1+input2)*input3;
13-
for(size_t i = 0; i < num_iter; i++) {
47+
for (size_t i = 0; i < num_iter; i++) {
1448
cppflow::tensor t1(input1), t2(input2), t3(input3);
1549
auto result = (t1+t2)*t3;
1650
float result_value = result.get_data<float>()[0];
17-
if(std::abs(target/result_value-1.0f) > 1e-6) {
18-
std::cout << "error: result_value=" << result_value << ", target=" << target << std::endl;
51+
if (std::abs(target/result_value-1.0f) > 1e-6) {
52+
std::cout << "error: result_value=" << result_value
53+
<< ", target=" << target << std::endl;
1954
}
2055
}
2156
}
2257

2358
int main() {
2459
std::vector<std::thread> threads;
25-
for(size_t i = 0; i < num_threads; i++) {
26-
if(i % 2 == 0) {
60+
for (size_t i = 0; i < num_threads; i++) {
61+
if (i % 2 == 0) {
2762
std::thread t1(test1, 3, 10, 100);
2863
threads.push_back(std::move(t1));
2964
} else {
@@ -32,7 +67,7 @@ int main() {
3267
}
3368
}
3469

35-
for(auto& t: threads) {
70+
for (auto& t : threads) {
3671
t.join();
3772
}
3873

examples/efficientnet/create_model.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,40 @@
1+
#!/usr/bin/env python
2+
3+
# MIT License
4+
#
5+
# Copyright (c) 2020 Sergio Izquierdo
6+
#
7+
# Permission is hereby granted, free of charge, to any person obtaining a copy
8+
# of this software and associated documentation files (the "Software"), to deal
9+
# in the Software without restriction, including without limitation the rights
10+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
# copies of the Software, and to permit persons to whom the Software is
12+
# furnished to do so, subject to the following conditions:
13+
#
14+
# The above copyright notice and this permission notice shall be included in
15+
# all copies or substantial portions of the Software.
16+
#
17+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
# SOFTWARE.
24+
25+
# @file create_model.py
26+
#
27+
# @brief A brief description here.
28+
#
29+
# @section description_create_model Define custom details for the file here.
30+
#
31+
# @section author_create_model Author(s)
32+
# - Created by Sergio Izquierdo
33+
34+
# Imports
135
import tensorflow as tf
236

337
model = tf.keras.applications.EfficientNetB0()
438

539
# Export the model to a SavedModel
640
model.save('model', save_format='tf')
7-
8-

examples/efficientnet/main.cpp

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,51 @@
1-
#include <iostream>
1+
// MIT License
2+
//
3+
// Copyright (c) 2020 Sergio Izquierdo
4+
// Copyright (c) 2021 Florian
5+
//
6+
// Permission is hereby granted, free of charge, to any person obtaining a copy
7+
// of this software and associated documentation files (the "Software"), to deal
8+
// in the Software without restriction, including without limitation the rights
9+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
// copies of the Software, and to permit persons to whom the Software is
11+
// furnished to do so, subject to the following conditions:
12+
//
13+
// The above copyright notice and this permission notice shall be included in
14+
// all copies or substantial portions of the Software.
15+
//
16+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
// SOFTWARE.
23+
24+
/*!
25+
* @file main.cpp
26+
* @brief A brief description here.
27+
* @details Define custom details for the file here.
28+
* @author Florian
29+
* @author Sergio Izquierdo
30+
* @date @showdate "%B %d, %Y" 2020-09-16
31+
*/
232

33+
// CppFlow headers
334
#include <cppflow/cppflow.h>
435

36+
// C++ headers
37+
#include <iostream>
538

639
int main() {
7-
8-
auto input = cppflow::decode_jpeg(cppflow::read_file(std::string(CAT_PATH)));
40+
auto input = cppflow::decode_jpeg(
41+
cppflow::read_file(std::string(CAT_PATH)));
942
input = cppflow::cast(input, TF_UINT8, TF_FLOAT);
1043
input = cppflow::expand_dims(input, 0);
1144
cppflow::model model(std::string(MODEL_PATH));
1245
auto output = model(input);
1346

14-
std::cout << "It's a tiger cat: " << cppflow::arg_max(output, 1) << std::endl;
47+
std::cout << "It's a tiger cat: " << cppflow::arg_max(output, 1)
48+
<< std::endl;
1549

1650
return 0;
1751
}

examples/load_frozen_graph/create_model.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,41 @@
1+
#!/usr/bin/env python
2+
3+
# MIT License
4+
#
5+
# Copyright (c) 2021 Daisuke Kato
6+
# Copyright (c) 2021 Paul
7+
# Copyright (c) 2022 Sergio Izquierdo
8+
#
9+
# Permission is hereby granted, free of charge, to any person obtaining a copy
10+
# of this software and associated documentation files (the "Software"), to deal
11+
# in the Software without restriction, including without limitation the rights
12+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
# copies of the Software, and to permit persons to whom the Software is
14+
# furnished to do so, subject to the following conditions:
15+
#
16+
# The above copyright notice and this permission notice shall be included in
17+
# all copies or substantial portions of the Software.
18+
#
19+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25+
# SOFTWARE.
26+
27+
# @file create_model.py
28+
#
29+
# @brief A brief description here.
30+
#
31+
# @section description_create_model Define custom details for the file here.
32+
#
33+
# @section author_create_model Author(s)
34+
# - Created by Daisuke Kato
35+
# - Created by Paul
36+
# - Modified by Sergio Izquierdo
37+
38+
# Imports
139
import tensorflow as tf
240
from tensorflow.python.framework.convert_to_constants import (
341
convert_variables_to_constants_v2,
@@ -19,4 +57,4 @@
1957

2058
# Save the graph as protobuf format
2159
directory = "."
22-
tf.io.write_graph(frozen_model.graph, directory, "model.pb", as_text=False)
60+
tf.io.write_graph(frozen_model.graph, directory, "model.pb", as_text=False)

examples/load_frozen_graph/main.cpp

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,50 @@
1-
#include <iostream>
1+
// MIT License
2+
//
3+
// Copyright (c) 2021 Daisuke Kato
4+
// Copyright (c) 2021 Paul
5+
// Copyright (c) 2022 Sergio Izquierdo
6+
//
7+
// Permission is hereby granted, free of charge, to any person obtaining a copy
8+
// of this software and associated documentation files (the "Software"), to deal
9+
// in the Software without restriction, including without limitation the rights
10+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
// copies of the Software, and to permit persons to whom the Software is
12+
// furnished to do so, subject to the following conditions:
13+
//
14+
// The above copyright notice and this permission notice shall be included in
15+
// all copies or substantial portions of the Software.
16+
//
17+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
// SOFTWARE.
24+
25+
/*!
26+
* @file main.cpp
27+
* @brief A brief description here.
28+
* @details Define custom details for the file here.
29+
* @author Daisuke Kato
30+
* @author Paul
31+
* @author Sergio Izquierdo
32+
* @date @showdate "%B %d, %Y" 2021-09-16
33+
*/
234

35+
// CppFlow headers
336
#include <cppflow/ops.h>
437
#include <cppflow/model.h>
538

39+
// C++ headers
40+
#include <iostream>
641

742
int main() {
8-
943
auto input = cppflow::fill({10, 5}, 1.0f);
1044
std::cout << "start" << std::endl;
1145
cppflow::model model("../model.pb", cppflow::model::FROZEN_GRAPH);
1246
auto output = model({{"x:0", input}}, {{"Identity:0"}})[0];
13-
47+
1448
std::cout << output << std::endl;
1549

1650
auto values = output.get_data<float>();
Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,40 @@
1+
#!/usr/bin/env python
2+
3+
# MIT License
4+
#
5+
# Copyright (c) 2019 Sergio Izquierdo
6+
#
7+
# Permission is hereby granted, free of charge, to any person obtaining a copy
8+
# of this software and associated documentation files (the "Software"), to deal
9+
# in the Software without restriction, including without limitation the rights
10+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
# copies of the Software, and to permit persons to whom the Software is
12+
# furnished to do so, subject to the following conditions:
13+
#
14+
# The above copyright notice and this permission notice shall be included in
15+
# all copies or substantial portions of the Software.
16+
#
17+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
# SOFTWARE.
24+
25+
# @file create_model.py
26+
#
27+
# @brief A brief description here.
28+
#
29+
# @section description_create_model Define custom details for the file here.
30+
#
31+
# @section author_create_model Author(s)
32+
# - Created by Sergio Izquierdo
33+
34+
# Imports
135
import tensorflow as tf
236
import numpy as np
337

4-
538
input = tf.keras.Input(shape=(5,))
639

740
output = tf.keras.layers.Dense(5, activation=tf.nn.relu)(input)
@@ -11,4 +44,4 @@
1144
model.compile()
1245

1346
# Export the model to a SavedModel
14-
model.save('model', save_format='tf')
47+
model.save('model', save_format='tf')

0 commit comments

Comments
 (0)