Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added more descriptive error logging #140

Merged
merged 2 commits into from
Jul 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions deployment/libtorch/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ std::vector<std::string> LoadNames(const std::string& path) {
// load class names
std::vector<std::string> class_names;
std::ifstream infile(path);
if (infile.is_open()) {
if (infile.good()) {
std::string line;
while (getline (infile, line)) {
class_names.emplace_back(line);
}
infile.close();
}
else {
std::cerr << "Error loading the class names!\n";
std::cerr << ">>> ERROR: Failed to access class name path: " << path
<< "\n>>>\tDoes the file exist? Permission to read it?\n";
}

return class_names;
Expand Down Expand Up @@ -123,18 +124,29 @@ int main(int argc, char* argv[]) {

// load input image
std::string image_path = cmd.get<std::string>("input_source");
if (std::ifstream(image_path).fail()) {
std::cerr << ">>> ERROR: Failed to access image file path: " << image_path
<< "\n>>>\tDoes the file exist? Permission to read it?\n";
return -1;
}

torch::jit::script::Module module;
try {
std::cout << ">>> Loading model" << std::endl;
// Deserialize the ScriptModule from a file using torch::jit::load().
std::string weights = cmd.get<std::string>("checkpoint");
if (std::ifstream(weights).fail()) {
std::cerr << ">>> ERROR: Failed to access checkpoint file path: " << weights
<< "\n>>>\tDoes the file exist? Permission to read it?\n";
return -1;
}

module = torch::jit::load(weights);
module.to(device_type);
module.eval();
std::cout << ">>> Model loaded" << std::endl;
} catch (const torch::Error& e) {
std::cout << ">>> error loading the model" << std::endl;
std::cout << ">>> Error loading the model: " << e.what() << std::endl;
return -1;
} catch (const std::exception& e) {
std::cout << ">>> Other error: " << e.what() << std::endl;
Expand Down