Repository: mlcommons/GaNDLF

Issue:
Training process is crashing if OpenVINO is not found in the environment
**Describe the bug**
When OpenVINO is not present in the environment, the training process crashes after a single epoch.

**To Reproduce**
Steps to reproduce the behavior:
1. Ensure OpenVINO is not installed in the environment (even `mo` should not be present)
2. Run `python -c "from testing.test_full import test_train_inference_optimize_segmentation_rad_2d;test_train_inference_optimize_segmentation_rad_2d('cpu')"`
3. See error:
```powershell
[SNIP!]
FileNotFoundError: [WinError 2] The system cannot find the file specified
```
OR:
```bash
[SNIP!]
Best model could not be loaded, error:  [Errno 2] No such file or directory: 'mo'
```

**Expected behavior**
If `mo` or openvino is not found, continue the training process, just without doing any post-training optimization.

**Screenshots**
N.A.

**GaNDLF Version**
<!-- Put the output of the following command:
python -c 'import GANDLF as g;print(g.__version__)'
-->
0.0.16-dev

**Desktop (please complete the following information):**
N.A.

**Additional context**
N.A.


Discussion:

Resolving patch:
diff --git a/GANDLF/utils/modelio.py b/GANDLF/utils/modelio.py
--- a/GANDLF/utils/modelio.py
+++ b/GANDLF/utils/modelio.py
@@ -85,41 +85,50 @@ def optimize_and_save_model(model, params, path, onnx_export=True):
             print("WARNING: Cannot export to ONNX model.")
             return
 
+        # https://github.com/mlcommons/GaNDLF/issues/605
+        openvino_present = False
         try:
-            if model_dimension == 2:
-                subprocess.call(
-                    [
-                        "mo",
-                        "--input_model",
-                        "{0}".format(onnx_path),
-                        "--input_shape",
-                        "[1,{0},{1},{2}]".format(
-                            num_channel, input_shape[0], input_shape[1]
-                        ),
-                        "--data_type",
-                        "{0}".format(ov_output_data_type),
-                        "--output_dir",
-                        "{0}".format(ov_output_dir),
-                    ],
-                )
-            else:
-                subprocess.call(
-                    [
-                        "mo",
-                        "--input_model",
-                        "{0}".format(onnx_path),
-                        "--input_shape",
-                        "[1,{0},{1},{2},{3}]".format(
-                            num_channel, input_shape[0], input_shape[1], input_shape[2]
-                        ),
-                        "--data_type",
-                        "{0}".format(ov_output_data_type),
-                        "--output_dir",
-                        "{0}".format(ov_output_dir),
-                    ],
-                )
-        except subprocess.CalledProcessError:
-            print("WARNING: OpenVINO Model Optimizer IR conversion failed.")
+            import openvino
+            openvino_present = True
+        except ImportError:
+            print("WARNING: OpenVINO is not present.")
+        
+        if openvino_present:
+            try:
+                if model_dimension == 2:
+                    subprocess.call(
+                        [
+                            "mo",
+                            "--input_model",
+                            "{0}".format(onnx_path),
+                            "--input_shape",
+                            "[1,{0},{1},{2}]".format(
+                                num_channel, input_shape[0], input_shape[1]
+                            ),
+                            "--data_type",
+                            "{0}".format(ov_output_data_type),
+                            "--output_dir",
+                            "{0}".format(ov_output_dir),
+                        ],
+                    )
+                else:
+                    subprocess.call(
+                        [
+                            "mo",
+                            "--input_model",
+                            "{0}".format(onnx_path),
+                            "--input_shape",
+                            "[1,{0},{1},{2},{3}]".format(
+                                num_channel, input_shape[0], input_shape[1], input_shape[2]
+                            ),
+                            "--data_type",
+                            "{0}".format(ov_output_data_type),
+                            "--output_dir",
+                            "{0}".format(ov_output_dir),
+                        ],
+                    )
+            except subprocess.CalledProcessError:
+                print("WARNING: OpenVINO Model Optimizer IR conversion failed.")
 
 
 def save_model(model_dict, model, params, path, onnx_export=True):


Test patch: