mirror of
https://github.com/lltcggie/waifu2x-caffe.git
synced 2025-06-26 13:42:48 +00:00
GUIで処理時間を表示するようにしてみた
This commit is contained in:
parent
07d24de9ed
commit
91128d864b
@ -7,6 +7,7 @@
|
||||
#include <tclap/CmdLine.h>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <chrono>
|
||||
|
||||
#if defined(WIN32) || defined(WIN64)
|
||||
#include <Windows.h>
|
||||
@ -406,11 +407,13 @@ eWaifu2xError ReconstructImage(boost::shared_ptr<caffe::Net<float>> net, cv::Mat
|
||||
|
||||
eWaifu2xError waifu2x(int argc, char** argv, const std::vector<InputOutputPathPair> &file_paths,
|
||||
const std::string &mode, const int noise_level, const double scale_ratio, const std::string &model_dir, const std::string &process,
|
||||
std::vector<PathAndErrorPair> &errors, const waifu2xCancelFunc cancel_func, const waifu2xProgressFunc progress_func)
|
||||
std::vector<PathAndErrorPair> &errors, const waifu2xCancelFunc cancel_func, const waifu2xProgressFunc progress_func, const waifu2xTimeFunc time_func)
|
||||
{
|
||||
if (scale_ratio <= 0.0)
|
||||
return eWaifu2xError_InvalidParameter;
|
||||
|
||||
const auto StartTime = std::chrono::system_clock::now();
|
||||
|
||||
eWaifu2xError ret;
|
||||
|
||||
std::call_once(waifu2x_once_flag, [argc, argv]()
|
||||
@ -424,6 +427,8 @@ eWaifu2xError waifu2x(int argc, char** argv, const std::vector<InputOutputPathPa
|
||||
caffe::GlobalInit(&tmpargc, &tmpargv);
|
||||
});
|
||||
|
||||
const auto cuDNNCheckStartTime = std::chrono::system_clock::now();
|
||||
|
||||
std::string process_fix(process);
|
||||
if (process_fix == "gpu")
|
||||
{
|
||||
@ -432,6 +437,8 @@ eWaifu2xError waifu2x(int argc, char** argv, const std::vector<InputOutputPathPa
|
||||
process_fix = "cudnn";
|
||||
}
|
||||
|
||||
const auto cuDNNCheckEndTime = std::chrono::system_clock::now();
|
||||
|
||||
boost::filesystem::path mode_dir_path(model_dir);
|
||||
if (!mode_dir_path.is_absolute()) // model_dirが相対パスなら絶対パスに直す
|
||||
{
|
||||
@ -484,6 +491,8 @@ eWaifu2xError waifu2x(int argc, char** argv, const std::vector<InputOutputPathPa
|
||||
return ret;
|
||||
}
|
||||
|
||||
const auto InitEndTime = std::chrono::system_clock::now();
|
||||
|
||||
int fileCount = 0;
|
||||
for (const auto &p : file_paths)
|
||||
{
|
||||
@ -632,5 +641,15 @@ eWaifu2xError waifu2x(int argc, char** argv, const std::vector<InputOutputPathPa
|
||||
if (progress_func)
|
||||
progress_func(file_paths.size(), fileCount);
|
||||
|
||||
const auto ProcessEndTime = std::chrono::system_clock::now();
|
||||
|
||||
const auto cuDNNCheckTime = (cuDNNCheckEndTime - cuDNNCheckStartTime);
|
||||
const auto InitTime = (InitEndTime - StartTime) - cuDNNCheckTime;
|
||||
const auto ProcessTime = (ProcessEndTime - InitEndTime);
|
||||
if (time_func)
|
||||
time_func(std::chrono::duration_cast<std::chrono::milliseconds>(InitTime).count()
|
||||
, std::chrono::duration_cast<std::chrono::milliseconds>(cuDNNCheckTime).count()
|
||||
, std::chrono::duration_cast<std::chrono::milliseconds>(ProcessTime).count());
|
||||
|
||||
return eWaifu2xError_OK;
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
@ -22,6 +23,7 @@ typedef std::pair<std::string, std::string> InputOutputPathPair;
|
||||
typedef std::pair<InputOutputPathPair, eWaifu2xError> PathAndErrorPair;
|
||||
typedef std::function<bool()> waifu2xCancelFunc;
|
||||
typedef std::function<void(const int ProgressFileMax, const int ProgressFileNow)> waifu2xProgressFunc;
|
||||
typedef std::function<void(const uint64_t InitTime, const uint64_t cuDNNCheckTime, const uint64_t ProcessTime)> waifu2xTimeFunc;
|
||||
|
||||
bool can_use_cuDNN();
|
||||
|
||||
@ -29,4 +31,4 @@ bool can_use_cuDNN();
|
||||
// process: cpu or gpu or cudnn
|
||||
eWaifu2xError waifu2x(int argc, char** argv,
|
||||
const std::vector<InputOutputPathPair> &file_paths, const std::string &mode, const int noise_level, const double scale_ratio, const std::string &model_dir, const std::string &process,
|
||||
std::vector<PathAndErrorPair> &errors, const waifu2xCancelFunc cancel_func = nullptr, const waifu2xProgressFunc progress_func = nullptr);
|
||||
std::vector<PathAndErrorPair> &errors, const waifu2xCancelFunc cancel_func = nullptr, const waifu2xProgressFunc progress_func = nullptr, const waifu2xTimeFunc time_func = nullptr);
|
||||
|
Binary file not shown.
@ -17,6 +17,7 @@
|
||||
#define WM_FAILD_CREATE_DIR (WM_APP + 5)
|
||||
#define WM_END_WAIFU2X (WM_APP + 6)
|
||||
#define WM_END_THREAD (WM_APP + 7)
|
||||
#define WM_TIME_WAIFU2X (WM_APP + 8)
|
||||
|
||||
const size_t AR_PATH_MAX(1024);
|
||||
|
||||
@ -82,6 +83,13 @@ private:
|
||||
std::string autoSetAddName;
|
||||
bool isLastError;
|
||||
|
||||
struct stWaifu2xTime
|
||||
{
|
||||
uint64_t InitTime;
|
||||
uint64_t cuDNNCheckTime;
|
||||
uint64_t ProcessTime;
|
||||
};
|
||||
|
||||
private:
|
||||
std::string AddName() const
|
||||
{
|
||||
@ -264,11 +272,21 @@ private:
|
||||
SendMessage(GetDlgItem(dh, IDC_PROGRESS), PBM_SETPOS, ProgressFileNow, 0);
|
||||
};
|
||||
|
||||
const auto TimeFunc = [this](const uint64_t InitTime, const uint64_t cuDNNCheckTime, const uint64_t ProcessTime)
|
||||
{
|
||||
stWaifu2xTime t;
|
||||
t.InitTime = InitTime;
|
||||
t.cuDNNCheckTime = cuDNNCheckTime;
|
||||
t.ProcessTime = ProcessTime;
|
||||
|
||||
SendMessage(dh, WM_TIME_WAIFU2X, (WPARAM)&t, 0);
|
||||
};
|
||||
|
||||
std::vector<PathAndErrorPair> errors;
|
||||
const eWaifu2xError ret = waifu2x(__argc, __argv, file_paths, mode, noise_level, scale_ratio, "models", process, errors, [this]()
|
||||
{
|
||||
return cancelFlag;
|
||||
}, ProgessFunc);
|
||||
}, ProgessFunc, TimeFunc);
|
||||
|
||||
SendMessage(dh, WM_END_WAIFU2X, (WPARAM)&ret, (LPARAM)&errors);
|
||||
|
||||
@ -347,6 +365,43 @@ public:
|
||||
MessageBeep(MB_ICONASTERISK);
|
||||
}
|
||||
|
||||
void Waifu2xTime(HWND hWnd, WPARAM wParam, LPARAM lParam, LPVOID lpData)
|
||||
{
|
||||
const stWaifu2xTime *tp = (const stWaifu2xTime *)wParam;
|
||||
|
||||
char msg[1024*2];
|
||||
char *ptr = msg;
|
||||
|
||||
{
|
||||
uint64_t t = tp->ProcessTime;
|
||||
const int msec = t % 1000; t /= 1000;
|
||||
const int sec = t % 60; t /= 60;
|
||||
const int min = t % 60; t /= 60;
|
||||
const int hour = (int)t;
|
||||
ptr += sprintf(ptr, "処理時間: %02d:%02d:%02d.%d\r\n", hour, min, sec, msec);
|
||||
}
|
||||
|
||||
{
|
||||
uint64_t t = tp->InitTime;
|
||||
const int msec = t % 1000; t /= 1000;
|
||||
const int sec = t % 60; t /= 60;
|
||||
const int min = t % 60; t /= 60;
|
||||
const int hour = (int)t;
|
||||
ptr += sprintf(ptr, "初期化時間: %02d:%02d:%02d.%d\r\n", hour, min, sec, msec);
|
||||
}
|
||||
|
||||
{
|
||||
uint64_t t = tp->cuDNNCheckTime;
|
||||
const int msec = t % 1000; t /= 1000;
|
||||
const int sec = t % 60; t /= 60;
|
||||
const int min = t % 60; t /= 60;
|
||||
const int hour = (int)t;
|
||||
ptr += sprintf(ptr, "cuDNNチェック時間: %02d:%02d:%02d.%d", hour, min, sec, msec);
|
||||
}
|
||||
|
||||
SetWindowTextA(GetDlgItem(hWnd, IDC_EDIT_LOG), msg);
|
||||
}
|
||||
|
||||
void OnDialogEnd(HWND hWnd, WPARAM wParam, LPARAM lParam, LPVOID lpData)
|
||||
{
|
||||
if (!processThread.joinable())
|
||||
@ -594,6 +649,7 @@ int WINAPI WinMain(HINSTANCE hInstance,
|
||||
cDialog.SetEventCallBack(SetClassFunc(DialogEvent::OnFaildCreateDir, &cDialogEvent), NULL, WM_FAILD_CREATE_DIR);
|
||||
cDialog.SetEventCallBack(SetClassFunc(DialogEvent::OnEndWaifu2x, &cDialogEvent), NULL, WM_END_WAIFU2X);
|
||||
cDialog.SetEventCallBack(SetClassFunc(DialogEvent::WaitThreadExit, &cDialogEvent), NULL, WM_END_THREAD);
|
||||
cDialog.SetEventCallBack(SetClassFunc(DialogEvent::Waifu2xTime, &cDialogEvent), NULL, WM_TIME_WAIFU2X);
|
||||
|
||||
// ƒ_ƒCƒAƒ<41>ƒO‚ð•\ަ
|
||||
cDialog.DoModal(hInstance, IDD_DIALOG);
|
||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user