Skip to content

Commit

Permalink
fix size_t and dims
Browse files Browse the repository at this point in the history
  • Loading branch information
Semyon1104 committed Nov 29, 2024
1 parent d95d3b6 commit f935fa3
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 13 deletions.
10 changes: 5 additions & 5 deletions app/Graph/build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void build_graph(Tensor input, Tensor output) {
tensor.get_shape()[0],
std::vector<float>(tensor.get_shape()[1], 0.0f));
int q = 0;
for (int i = 0; i < Values_vector.size(); i++) {
for (size_t i = 0; i < Values_vector.size(); i++) {
Values_vector_2d[q][i - (q * tensor.get_shape()[1])] = Values_vector[i];
if ((i + 1) % tensor.get_shape()[1] == 0) {
q++;
Expand All @@ -50,17 +50,17 @@ void build_graph(Tensor input, Tensor output) {
tensor.get_shape()[1],
std::vector<float>(tensor.get_shape()[0], 0.0f));

for (int i = 0; i < tensor.get_shape()[0]; ++i) {
for (int j = 0; j < tensor.get_shape()[1]; ++j) {
for (size_t i = 0; i < tensor.get_shape()[0]; ++i) {
for (size_t j = 0; j < tensor.get_shape()[1]; ++j) {
Values_vector_2d_2[j][i] = Values_vector_2d[i][j];
}
}
std::vector<float> Values_vector_1d(
tensor.get_shape()[0] * tensor.get_shape()[1], 0.0f);
int index_1d = 0;

for (int j = 0; j < tensor.get_shape()[1]; ++j) {
for (int k = 0; k < tensor.get_shape()[0]; ++k) {
for (size_t j = 0; j < tensor.get_shape()[1]; ++j) {
for (size_t k = 0; k < tensor.get_shape()[0]; ++k) {
Values_vector_1d[index_1d++] = Values_vector_2d_2[j][k];
}
}
Expand Down
3 changes: 2 additions & 1 deletion app/Graph/build.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include <iostream>
#include <opencv2/opencv.hpp>
#include <stdexcept>
#include <variant>
#include <vector>
#include <opencv2/opencv.hpp>

#include "Weights_Reader/reader_weights.hpp"
#include "graph/graph.hpp"
#include "layers/ConvLayer.hpp"
Expand Down
6 changes: 3 additions & 3 deletions app/Graph/graph_build.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "build.hpp"
#include "build.cpp"
#include "build.hpp"

using namespace itlab_2023;

Expand All @@ -13,15 +13,15 @@ int main() {
cv::cvtColor(image, image, cv::COLOR_BGR2GRAY);
cv::resize(image, resized_image, cv::Size(28, 28));
std::vector<cv::Mat> channels;

cv::split(resized_image, channels);

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

for (int i = 0; i < 28; ++i) {
for (int j = 0; j < 28; ++j) {
res[i * 28 + j] = channels[0].at<uchar>(i,j);
res[i * 28 + j] = channels[0].at<uchar>(i, j);
}
}
Shape sh({static_cast<size_t>(count_pic), 28, 28, 1});
Expand Down
3 changes: 1 addition & 2 deletions include/Weights_Reader/reader_weights.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ using namespace itlab_2023;
json read_json(const std::string& filename);
void extract_values_without_bias(const json& j, std::vector<float>& values);
void extract_values_from_json(const json& j, std::vector<float>& values);
void parse_json_shape(const json& j, std::vector<size_t>& shape,
size_t dim);
void parse_json_shape(const json& j, std::vector<size_t>& shape, size_t dim);
Tensor create_tensor_from_json(const json& j, Type type);
void extract_bias_from_json(const json& j, std::vector<float>& bias);
5 changes: 3 additions & 2 deletions src/Weights_Reader/reader_weights.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ void extract_values_without_bias(const json& j, std::vector<float>& values) {
}
}

void parse_json_shape(const json& j, std::vector<size_t>& shape, size_t dim = 0) {
void parse_json_shape(const json& j, std::vector<size_t>& shape,
size_t dim) {
if (dim == 0) {
if (j.is_array()) {
if (j.empty()) {
Expand Down Expand Up @@ -98,7 +99,7 @@ Tensor create_tensor_from_json(const json& j, Type type) {
extract_values_without_bias(j, vals);
std::cout << "Extracted values size: " << vals.size() << std::endl;

parse_json_shape(j, shape);
parse_json_shape(j, shape, 0);
std::cout << "Parsed shape: ";
size_t expected_size = 1;
for (const auto& dim : shape) {
Expand Down

0 comments on commit f935fa3

Please sign in to comment.