From 1c944e01eaf564f6d04dfd6b35b6b6bbdb9927f6 Mon Sep 17 00:00:00 2001 From: lltcggie Date: Sat, 26 Dec 2015 18:31:36 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=91=E3=83=A9=E3=83=A1=E3=83=BC=E3=82=BF?= =?UTF-8?q?=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB=E3=81=8Cjson=E3=81=97?= =?UTF-8?q?=E3=81=8B=E3=81=AA=E3=81=84=E5=A0=B4=E5=90=88=E3=80=81=E3=83=90?= =?UTF-8?q?=E3=82=A4=E3=83=8A=E3=83=AA=E3=81=AB=E5=A4=89=E6=8F=9B=E3=81=99?= =?UTF-8?q?=E3=82=8B=E6=A9=9F=E8=83=BD=E3=81=8C=E5=8B=95=E3=81=84=E3=81=A6?= =?UTF-8?q?=E3=81=84=E3=81=AA=E3=81=8B=E3=81=A3=E3=81=9F=E3=81=AE=E3=82=92?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/waifu2x.cpp | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/common/waifu2x.cpp b/common/waifu2x.cpp index 84a849c..ee0061e 100644 --- a/common/waifu2x.cpp +++ b/common/waifu2x.cpp @@ -242,10 +242,19 @@ static Waifu2x::eWaifu2xError readProtoText(const boost::filesystem::path &path, static Waifu2x::eWaifu2xError readProtoBinary(const boost::filesystem::path &path, ::google::protobuf::Message* proto) { - boost::iostreams::stream is(path, std::ios_base::in | std::ios_base::binary); + boost::iostreams::stream is; + + try + { + is.open(path, std::ios_base::in | std::ios_base::binary); + } + catch (...) + { + return Waifu2x::eWaifu2xError_FailedOpenModelFile; + } if (!is) - return Waifu2x::eWaifu2xError_FailedParseModelFile; + return Waifu2x::eWaifu2xError_FailedOpenModelFile; std::vector tmp; if (!readFile(is, tmp)) @@ -617,7 +626,12 @@ Waifu2x::eWaifu2xError Waifu2x::ConstractNet(boost::shared_ptr modelbin_path += ".protobin"; caffe::NetParameter param; - if (readProtoBinary(modelbin_path, ¶m) == eWaifu2xError_OK) + caffe::NetParameter param_caffemodel; + + const auto retModelBin = readProtoBinary(caffemodel_path, ¶m); + const auto retParamBin = readProtoBinary(modelbin_path, ¶m_caffemodel); + + if (retModelBin == eWaifu2xError_OK && retParamBin == eWaifu2xError_OK) { Waifu2x::eWaifu2xError ret; @@ -625,11 +639,6 @@ Waifu2x::eWaifu2xError Waifu2x::ConstractNet(boost::shared_ptr if (ret != eWaifu2xError_OK) return ret; - caffe::NetParameter param_caffemodel; - ret = readProtoBinary(caffemodel_path, ¶m_caffemodel); - if (ret != eWaifu2xError_OK) - return ret; - if (!caffe::UpgradeNetAsNeeded(caffemodel_path.string(), ¶m_caffemodel)) return Waifu2x::eWaifu2xError_FailedParseModelFile;