Repository: mlcommons/GaNDLF

Issue:
Error In Classification Tasks -- `perform_sanity_check_on_subject` Function
**Describe the bug**
When running GaNDLF, error occured in  638th line of utils.py file. That is due to subject[str(key)] = "NA" and it does not have "path" key value since it is just string.

**To Reproduce**
Steps to reproduce the behavior:
1. Run GaNDLF with the configuration I attached.
2. Error should occur before the training started.


**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
![image](https://user-images.githubusercontent.com/24361544/126798290-e34590c5-acaa-43bc-be2e-b6f677d61973.png)

**GaNDLF Version**
11

**Desktop (please complete the following information):**
 - Linux WSL 20.04

**Additional context**
[mini_training_data_2.txt](https://github.com/CBICA/GaNDLF/files/6869487/mini_training_data_2.txt)
[config_classification.txt](https://github.com/CBICA/GaNDLF/files/6869488/config_classification.txt)




Discussion:
Can you insert the following line in L634 in utils.py and post the output:

```python
print(list_for_comparison)
```
Here it is:

------List of Comparison------
[1, 'label']
------------------------------
There is something weird going on, because the CSV only contains the following and no label:

```
SubjectID,Channel_0,ValueToPredict
```

Let me see if I can reproduce this on my end.

Resolving patch:
diff --git a/GANDLF/utils.py b/GANDLF/utils.py
--- a/GANDLF/utils.py
+++ b/GANDLF/utils.py
@@ -629,46 +629,53 @@ def perform_sanity_check_on_subject(subject, parameters):
     import copy
 
     list_for_comparison = copy.deepcopy(parameters["headers"]["channelHeaders"])
-    if "labelHeader" in parameters["headers"]:
+    if parameters["headers"]["labelHeader"] is not None:
         list_for_comparison.append("label")
 
-    for key in list_for_comparison:
-        if file_reader_base is None:
-            file_reader_base = sitk.ImageFileReader()
-            file_reader_base.SetFileName(subject[str(key)]["path"])
-            file_reader_base.ReadImageInformation()
-        else:
-            # in this case, file_reader_base is ready
-            file_reader_current = sitk.ImageFileReader()
-            file_reader_current.SetFileName(subject[str(key)]["path"])
-            file_reader_current.ReadImageInformation()
-
-            if file_reader_base.GetDimension() != file_reader_current.GetDimension():
-                raise ValueError(
-                    "Dimensions for Subject '"
-                    + subject["subject_id"]
-                    + "' are not consistent."
-                )
-
-            if file_reader_base.GetOrigin() != file_reader_current.GetOrigin():
-                raise ValueError(
-                    "Origin for Subject '"
-                    + subject["subject_id"]
-                    + "' are not consistent."
-                )
-
-            if file_reader_base.GetDirection() != file_reader_current.GetDirection():
-                raise ValueError(
-                    "Orientation for Subject '"
-                    + subject["subject_id"]
-                    + "' are not consistent."
-                )
-
-            if file_reader_base.GetSpacing() != file_reader_current.GetSpacing():
-                raise ValueError(
-                    "Spacing for Subject '"
-                    + subject["subject_id"]
-                    + "' are not consistent."
-                )
+    if len(list_for_comparison) > 1:
+        for key in list_for_comparison:
+            if file_reader_base is None:
+                file_reader_base = sitk.ImageFileReader()
+                file_reader_base.SetFileName(subject[str(key)]["path"])
+                file_reader_base.ReadImageInformation()
+            else:
+                # in this case, file_reader_base is ready
+                file_reader_current = sitk.ImageFileReader()
+                file_reader_current.SetFileName(subject[str(key)]["path"])
+                file_reader_current.ReadImageInformation()
+
+                if (
+                    file_reader_base.GetDimension()
+                    != file_reader_current.GetDimension()
+                ):
+                    raise ValueError(
+                        "Dimensions for Subject '"
+                        + subject["subject_id"]
+                        + "' are not consistent."
+                    )
+
+                if file_reader_base.GetOrigin() != file_reader_current.GetOrigin():
+                    raise ValueError(
+                        "Origin for Subject '"
+                        + subject["subject_id"]
+                        + "' are not consistent."
+                    )
+
+                if (
+                    file_reader_base.GetDirection()
+                    != file_reader_current.GetDirection()
+                ):
+                    raise ValueError(
+                        "Orientation for Subject '"
+                        + subject["subject_id"]
+                        + "' are not consistent."
+                    )
+
+                if file_reader_base.GetSpacing() != file_reader_current.GetSpacing():
+                    raise ValueError(
+                        "Spacing for Subject '"
+                        + subject["subject_id"]
+                        + "' are not consistent."
+                    )
 
     return True


Test patch: