-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into AndreySorokin7/accuracy_verification
- Loading branch information
Showing
34 changed files
with
966 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
add_executable(Reader_weights reader_weights_sample.cpp) | ||
|
||
target_link_libraries(Reader_weights PUBLIC perf_lib layers_lib reader_lib) | ||
|
||
add_definitions(-DMODEL_PATH="${CMAKE_SOURCE_DIR}/docs/model_data_alexnet_1.json") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,46 @@ | ||
import tensorflow as tf | ||
from tensorflow.keras.models import load_model | ||
import pickle | ||
import joblib | ||
# Путь к вашей модели .h5 | ||
MODEL_PATH = 'AlexNet-model.h5' | ||
import json | ||
import numpy as np | ||
import os | ||
|
||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | ||
MODEL_PATH = os.path.join(BASE_DIR, 'docs', 'AlexNet-model.h5') | ||
MODEL_DATA_PATH = os.path.join(BASE_DIR, 'docs', 'model_data_alexnet_1.json') | ||
|
||
|
||
# Загрузка модели | ||
model = load_model(MODEL_PATH) | ||
|
||
# Получение графа модели | ||
graph = tf.compat.v1.get_default_graph() | ||
|
||
# Получение весов модели | ||
weights = model.get_weights() | ||
|
||
MODEL_DATA_PATH = 'model_data_alexnet.joblib' | ||
|
||
# Сохранение имен слоев и весов модели | ||
layer_weights = {} | ||
for layer in model.layers: | ||
layer_name = layer.name | ||
layer_weights[layer_name] = layer.get_weights() | ||
# Преобразование весов в списки для совместимости с JSON | ||
layer_weights[layer_name] = [w.tolist() for w in layer.get_weights()] | ||
|
||
with open(MODEL_DATA_PATH, 'wb') as f: | ||
joblib.dump(layer_weights, f) | ||
# Сохранение данных в JSON файл | ||
with open(MODEL_DATA_PATH, 'w') as f: | ||
json.dump(layer_weights, f, indent=2) # добавляем отступы для лучшей читаемости | ||
|
||
print(f"Model data saved to {MODEL_DATA_PATH}") | ||
|
||
# Загрузка данных | ||
loaded_model_data = joblib.load(MODEL_DATA_PATH) | ||
with open(MODEL_DATA_PATH, 'r') as f: | ||
loaded_model_data = json.load(f) | ||
|
||
# Преобразование данных обратно в numpy массивы | ||
for layer_name, weights in loaded_model_data.items(): | ||
loaded_model_data[layer_name] = [np.array(w) for w in weights] | ||
|
||
# Вывод данных | ||
print("Model layers and weights:") | ||
for layer_name, weights in loaded_model_data.items(): | ||
print("Layer:", layer_name) | ||
print("Weights:", weights) | ||
for weight in weights: | ||
print(weight) | ||
print() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include <iostream> | ||
|
||
#include "Weights_Reader/reader_weights.hpp" | ||
|
||
int main() { | ||
std::string json_file = MODEL_PATH; | ||
json model_data = read_json(json_file); | ||
|
||
for (auto& layer : model_data.items()) { | ||
std::string layer_name = layer.key(); | ||
std::cout << "Layer: " << layer_name << std::endl; | ||
|
||
try { | ||
Tensor tensor = create_tensor_from_json(layer.value(), Type::kFloat); | ||
std::cout << tensor << std::endl; | ||
} catch (const std::exception& e) { | ||
std::cerr << "Error processing layer " << layer_name << ": " << e.what() | ||
<< std::endl; | ||
} | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
add_subdirectory(ReaderImage) | ||
|
||
add_subdirectory(Accuracy) | ||
add_subdirectory(AlexNet) |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include <nlohmann/json.hpp> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "layers/Tensor.hpp" | ||
|
||
using json = nlohmann::json; | ||
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 = 0); | ||
Tensor create_tensor_from_json(const json& j, Type type); | ||
void extract_bias_from_json(const json& j, std::vector<float>& bias); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.