Skip to content

Commit f935fa3

Browse files
committed
fix size_t and dims
1 parent d95d3b6 commit f935fa3

File tree

5 files changed

+14
-13
lines changed

5 files changed

+14
-13
lines changed

app/Graph/build.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void build_graph(Tensor input, Tensor output) {
4040
tensor.get_shape()[0],
4141
std::vector<float>(tensor.get_shape()[1], 0.0f));
4242
int q = 0;
43-
for (int i = 0; i < Values_vector.size(); i++) {
43+
for (size_t i = 0; i < Values_vector.size(); i++) {
4444
Values_vector_2d[q][i - (q * tensor.get_shape()[1])] = Values_vector[i];
4545
if ((i + 1) % tensor.get_shape()[1] == 0) {
4646
q++;
@@ -50,17 +50,17 @@ void build_graph(Tensor input, Tensor output) {
5050
tensor.get_shape()[1],
5151
std::vector<float>(tensor.get_shape()[0], 0.0f));
5252

53-
for (int i = 0; i < tensor.get_shape()[0]; ++i) {
54-
for (int j = 0; j < tensor.get_shape()[1]; ++j) {
53+
for (size_t i = 0; i < tensor.get_shape()[0]; ++i) {
54+
for (size_t j = 0; j < tensor.get_shape()[1]; ++j) {
5555
Values_vector_2d_2[j][i] = Values_vector_2d[i][j];
5656
}
5757
}
5858
std::vector<float> Values_vector_1d(
5959
tensor.get_shape()[0] * tensor.get_shape()[1], 0.0f);
6060
int index_1d = 0;
6161

62-
for (int j = 0; j < tensor.get_shape()[1]; ++j) {
63-
for (int k = 0; k < tensor.get_shape()[0]; ++k) {
62+
for (size_t j = 0; j < tensor.get_shape()[1]; ++j) {
63+
for (size_t k = 0; k < tensor.get_shape()[0]; ++k) {
6464
Values_vector_1d[index_1d++] = Values_vector_2d_2[j][k];
6565
}
6666
}

app/Graph/build.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#include <iostream>
2+
#include <opencv2/opencv.hpp>
23
#include <stdexcept>
34
#include <variant>
45
#include <vector>
5-
#include <opencv2/opencv.hpp>
6+
67
#include "Weights_Reader/reader_weights.hpp"
78
#include "graph/graph.hpp"
89
#include "layers/ConvLayer.hpp"

app/Graph/graph_build.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#include "build.hpp"
21
#include "build.cpp"
2+
#include "build.hpp"
33

44
using namespace itlab_2023;
55

@@ -13,15 +13,15 @@ int main() {
1313
cv::cvtColor(image, image, cv::COLOR_BGR2GRAY);
1414
cv::resize(image, resized_image, cv::Size(28, 28));
1515
std::vector<cv::Mat> channels;
16-
16+
1717
cv::split(resized_image, channels);
1818

1919
int count_pic = 1;
2020
std::vector<float> res(count_pic * 28 * 28);
2121

2222
for (int i = 0; i < 28; ++i) {
2323
for (int j = 0; j < 28; ++j) {
24-
res[i * 28 + j] = channels[0].at<uchar>(i,j);
24+
res[i * 28 + j] = channels[0].at<uchar>(i, j);
2525
}
2626
}
2727
Shape sh({static_cast<size_t>(count_pic), 28, 28, 1});

include/Weights_Reader/reader_weights.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ using namespace itlab_2023;
1010
json read_json(const std::string& filename);
1111
void extract_values_without_bias(const json& j, std::vector<float>& values);
1212
void extract_values_from_json(const json& j, std::vector<float>& values);
13-
void parse_json_shape(const json& j, std::vector<size_t>& shape,
14-
size_t dim);
13+
void parse_json_shape(const json& j, std::vector<size_t>& shape, size_t dim);
1514
Tensor create_tensor_from_json(const json& j, Type type);
1615
void extract_bias_from_json(const json& j, std::vector<float>& bias);

src/Weights_Reader/reader_weights.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ void extract_values_without_bias(const json& j, std::vector<float>& values) {
5555
}
5656
}
5757

58-
void parse_json_shape(const json& j, std::vector<size_t>& shape, size_t dim = 0) {
58+
void parse_json_shape(const json& j, std::vector<size_t>& shape,
59+
size_t dim) {
5960
if (dim == 0) {
6061
if (j.is_array()) {
6162
if (j.empty()) {
@@ -98,7 +99,7 @@ Tensor create_tensor_from_json(const json& j, Type type) {
9899
extract_values_without_bias(j, vals);
99100
std::cout << "Extracted values size: " << vals.size() << std::endl;
100101

101-
parse_json_shape(j, shape);
102+
parse_json_shape(j, shape, 0);
102103
std::cout << "Parsed shape: ";
103104
size_t expected_size = 1;
104105
for (const auto& dim : shape) {

0 commit comments

Comments
 (0)