GOOGLE ADS

sábado, 23 de abril de 2022

SIGSEGV, Asignación de cadena C++ de falla de segmentación

Me encontré con un problema muy extraño. crear una instancia de clase usando argumentos de cadena directos no da ningún error, pero con pares obtengo una falla de segmentación:

 NeuralNetwork load_model(const std::string &file_name) {
std::ifstream in_file; // Ifstream to read file
in_file.open(file_name.c_str()); // Openinig file
// If there is any problem in opening file
if (!in_file.is_open()) {
std::cerr << "ERROR (" << __func__ << "): ";
std::cerr << "Unable to open file: " << file_name << std::endl;
std::exit(EXIT_FAILURE);
}
std::vector<std::pair<int, std::string>> config; // To store config
std::vector<std::vector<std::valarray<double>>>
kernels; // To store pretrained kernels
// Loading model from saved file format
size_t total_layers = 0;
in_file >> total_layers;
for (size_t i = 0; i < total_layers; i++) {
int neurons = 0;
std::string activation;
size_t shape_a = 0, shape_b = 0;
std::vector<std::valarray<double>> kernel;
in_file >> neurons >> activation >> shape_a >> shape_b;
for (size_t r = 0; r < shape_a; r++) {
std::valarray<double> row(shape_b);
for (size_t c = 0; c < shape_b; c++) {
in_file >> row[c];
}
kernel.push_back(row);
}
config.emplace_back(make_pair(neurons, activation));
;
kernels.emplace_back(kernel);
}
std::cout << "INFO: Model loaded successfully" << std::endl;
in_file.close(); // Closing file

string t1 = config.begin()->second; // string t1 = "none" works

machine_learning::neural_network::NeuralNetwork NNN =
machine_learning::neural_network::NeuralNetwork({
{12, t1}, // First layer with 3 neurons
{12, "tanh"}, // First layer with 3 neurons
{4, "tanh"} // First layer with 3 neurons
});
return NNN;
}

esta linea es el problema:

 string t1 = config.begin()->second;

al cambiarlo a esto no da ningún error:

string t1 = "none";

también he comprobado el valor del par que es exactamente el mismo ("ninguno")

Gracias.


Solución del problema

El problema se resolvió porque algunos de mis archivos estaban dañados, por lo que la variable de configuración estaba realmente vacía en algunos casos.

No hay comentarios:

Publicar un comentario

Regla de Firestore para acceder a la generación de subcolección Permisos faltantes o insuficientes

Tengo problemas con las reglas de Firestore para permitir el acceso a algunos recursos en una subcolección. Tengo algunos requests document...