Skip to content

Commit 8b598c0

Browse files
committed
Adding check for CLI mode, to hide some messages
1 parent 005a68b commit 8b598c0

File tree

6 files changed

+23
-2
lines changed

6 files changed

+23
-2
lines changed

Applications/shapeworks/Commands.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ bool DeepSSMCommand::execute(const optparse::Values& options, SharedCommandData&
421421
project->load(project_file);
422422

423423
PythonWorker python_worker;
424+
python_worker.set_cli_mode(true);
424425

425426
auto wait_for_job = [&](auto job) {
426427
// This lambda will block until the job is complete

Libs/Application/Job/PythonWorker.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,17 @@ class PythonLogger {
3737

3838
bool check_abort() { return aborted_; }
3939

40+
bool is_cli_mode() { return is_cli_mode_; }
41+
42+
void set_cli_mode(bool cli) { is_cli_mode_ = cli; }
43+
4044
private:
4145
std::function<void(std::string)> callback_;
4246
std::function<void(double, std::string)> progress_callback_;
4347

4448
std::atomic<bool> aborted_{false};
49+
50+
std::atomic<bool> is_cli_mode_{false};
4551
};
4652

4753
//---------------------------------------------------------------------------
@@ -50,7 +56,8 @@ PYBIND11_EMBEDDED_MODULE(logger, m) {
5056
.def(py::init<>())
5157
.def("log", &PythonLogger::cpp_log)
5258
.def("check_abort", &PythonLogger::check_abort)
53-
.def("progress", &PythonLogger::cpp_progress);
59+
.def("progress", &PythonLogger::cpp_progress)
60+
.def("is_cli_mode", &PythonLogger::is_cli_mode);
5461
};
5562

5663
//---------------------------------------------------------------------------
@@ -79,6 +86,9 @@ void PythonWorker::set_vtk_output_window(vtkSmartPointer<ShapeWorksVtkOutputWind
7986
studio_vtk_output_window_ = output_window;
8087
}
8188

89+
//---------------------------------------------------------------------------
90+
void PythonWorker::set_cli_mode(bool cli_mode) { python_logger_->set_cli_mode(cli_mode); }
91+
8292
//---------------------------------------------------------------------------
8393
void PythonWorker::start_job(QSharedPointer<Job> job) {
8494
if (init()) {

Libs/Application/Job/PythonWorker.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class PythonWorker : public QObject {
2424
~PythonWorker();
2525

2626
void set_vtk_output_window(vtkSmartPointer<ShapeWorksVtkOutputWindow> output_window);
27+
void set_cli_mode(bool cli_mode);
2728

2829
void run_job(QSharedPointer<Job> job);
2930
void set_current_job(QSharedPointer<Job> job);

Python/DeepSSMUtilsPackage/DeepSSMUtils/run_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,7 @@ def process_test_predictions(project, config_file):
538538
template_particles, template_mesh, pred_dir)
539539

540540
print("Distances: ", distances)
541+
print("Mean distance: ", np.mean(distances))
541542

542543
# write to csv file in deepssm_dir
543544
csv_file = f"{deepssm_dir}/test_distances.csv"

Python/DeepSSMUtilsPackage/DeepSSMUtils/trainer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ def supervised_train(config_file):
167167
if sw_check_abort():
168168
sw_message("Aborted")
169169
return
170-
sw_message(f"Epoch {e}/{num_epochs}")
170+
if not sw_is_cli_mode():
171+
sw_message(f"Epoch {e}/{num_epochs}")
171172
sw_progress(e / (num_epochs + 1))
172173

173174
torch.cuda.empty_cache()

Python/shapeworks/shapeworks/utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,13 @@ def sw_check_abort():
198198
else:
199199
return False
200200

201+
def sw_is_cli_mode():
202+
"""Check if the current mode is CLI mode"""
203+
global sw_logger
204+
if sw_logger is not None:
205+
return sw_logger.is_cli_mode()
206+
else:
207+
return False
201208

202209
def sw_progress(progress, message=""):
203210
"""If sw_logger is set, use it, otherwise do nothing"""

0 commit comments

Comments
 (0)