Skip to content

Commit e5c310f

Browse files
committed
noise_scaleとnoiseを両方持っているモデルに対応
1 parent 8b53d0f commit e5c310f

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

bin/models/cunet/info.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{"name":"CUnet","arch_name":"upcunet","has_noise_scale":true,"channels":3,
1+
{"name":"CUnet","arch_name":"upcunet","has_noise_scale":true,"has_noise_only":true, "channels":3,
22
"scale_factor":2,"offset":36,
33
"scale_factor_noise":1,"offset_noise":28
44
}

common/cNet.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,13 @@ Waifu2x::eWaifu2xError cNet::GetInfo(const boost::filesystem::path & info_path,
190190
const auto name = d["name"].GetString();
191191
const auto arch_name = d["arch_name"].GetString();
192192
const bool has_noise_scale = d.HasMember("has_noise_scale") && d["has_noise_scale"].GetBool() ? true : false;
193+
const bool has_noise_only = d.HasMember("has_noise_only") && d["has_noise_only"].GetBool() ? true : false;
193194
const int channels = d["channels"].GetInt();
194195

195196
info.name = name;
196197
info.arch_name = arch_name;
197198
info.has_noise_scale = has_noise_scale;
199+
info.has_noise_only = has_noise_only;
198200
info.channels = channels;
199201

200202
if (d.HasMember("offset"))

common/waifu2x.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ Waifu2x::eWaifu2xError Waifu2x::Init(const eWaifu2xModelType mode, const int noi
655655
if (ret != Waifu2x::eWaifu2xError_OK)
656656
return ret;
657657

658-
mHasNoiseScale = info.has_noise_scale;
658+
mHasNoiseScaleOnly = info.has_noise_scale && !info.has_noise_only;
659659
mInputPlane = info.channels;
660660

661661
if (mode == eWaifu2xModelTypeNoise || mode == eWaifu2xModelTypeNoiseScale || mode == eWaifu2xModelTypeAutoScale)
@@ -665,7 +665,7 @@ Waifu2x::eWaifu2xError Waifu2x::Init(const eWaifu2xModelType mode, const int noi
665665
mNoiseNet.reset(new cNet);
666666

667667
eWaifu2xModelType Mode = mode;
668-
if (info.has_noise_scale) // ノイズ除去と拡大を同時に行う
668+
if (mHasNoiseScaleOnly) // ノイズ除去と拡大を同時に行う
669669
{
670670
// ノイズ除去拡大ネットの構築はeWaifu2xModelTypeNoiseScaleを指定する必要がある
671671
Mode = eWaifu2xModelTypeNoiseScale;
@@ -905,7 +905,7 @@ Waifu2x::eWaifu2xError Waifu2x::ReconstructImage(const Factor factor, const int
905905

906906
if (isReconstructNoise)
907907
{
908-
if (!mHasNoiseScale) // ノイズ除去だけ
908+
if (!mHasNoiseScaleOnly) // ノイズ除去だけ
909909
{
910910
cv::Mat im;
911911
cv::Size_<int> size;

common/waifu2x.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class Waifu2x
7474
std::string name;
7575
std::string arch_name;
7676
bool has_noise_scale;
77+
bool has_noise_only;
7778
int channels;
7879

7980
stParam noise;
@@ -141,7 +142,7 @@ class Waifu2x
141142

142143
int mInputPlane; // ネットへの入力チャンネル数
143144
int mMaxNetOffset; // ネットに入力するとどれくらい削れるか
144-
bool mHasNoiseScale;
145+
bool mHasNoiseScaleOnly;
145146

146147
float *mOutputBlock;
147148
size_t mOutputBlockSize;

0 commit comments

Comments
 (0)