Repository: pytorch/ignite

Issue:
VOC example is broken
## 🐛 Bug description

This PR https://github.com/pytorch/ignite/pull/1605 breakes Pascal VOC example due to bad import:

```python
import torch
from apex import amp
from dataflow.datasets import VOCSegmentationOpencv  # <---- imported before sys.path.insert
from py_config_runner.config_utils import TRAINVAL_CONFIG, assert_config, get_params
from py_config_runner.utils import set_seed
from utils import exp_tracking  # <---- imported before sys.path.insert
from utils.handlers import predictions_gt_images_handler  # <---- imported before sys.path.insert

...

# Adds "code" folder to python path
sys.path.insert(0, Path(__file__).parent.parent.as_posix())
```


## Environment

 - PyTorch Version (e.g., 1.4):
 - Ignite Version (e.g., 0.3.0):
 - OS (e.g., Linux):
 - How you installed Ignite (`conda`, `pip`, source):
 - Python version:
 - Any other relevant information:



Discussion:
is this up @vfdev-5 
@sparkingdark unfortunately this one is for myself as it is a bit situation we have with this ref example.
I see it causing from previous pull req.where can I start contribute,any issue I requested more information about the projects listed for gsoc.can you guide @vfdev-5 
@sparkingdark I answered you there, please see https://github.com/pytorch/ignite/discussions/1603#discussioncomment-344799

Currently, we do not have any "good first issue", but you can check the list of "help wanted" issues like : 
- https://github.com/pytorch/ignite/issues/829
- https://github.com/pytorch/ignite/issues/1415
Others could be more bit tricky.

Maybe, you can try even fixing this issue by inspecting https://github.com/pytorch/ignite/issues/1616 PR and try to check if this is an issue with `isort` and could be fixed by reordering the imports...

Let me know about your choice.

@vfdev-5 I see that there is different apex project exists like nvidea one,i used this to install `apex` library 

```
git clone https://github.com/NVIDIA/apex
cd apex
pip install -v --disable-pip-version-check --no-cache-dir ./
```
But after that I got this error can you tell me which specific package need to install regarding dataflow

```
╰─ python3 voc.py         
Traceback (most recent call last):
  File "voc.py", line 3, in <module>
    from dataflow.datasets import VOCSegmentationOpencv  # <---- imported before sys.path.insert
ModuleNotFoundError: No module named 'dataflow'
```

Tried to install google-dataflow but got this error:

```
 pip3 install google-cloud-dataflow
Collecting google-cloud-dataflow
  Downloading google-cloud-dataflow-2.4.0.tar.gz (5.8 kB)
ERROR: Could not find a version that satisfies the requirement apache-beam[gcp]==2.4.0 (from google-cloud-dataflow) (from versions: 0.6.0, 2.0.0, 2.1.0, 2.1.1, 2.2.0, 2.11.0, 2.12.0, 2.13.0, 2.14.0, 2.15.0, 2.16.0, 2.17.0, 2.18.0, 2.19.0, 2.20.0, 2.21.0, 2.22.0, 2.23.0, 2.24.0, 2.25.0, 2.26.0, 2.27.0)
ERROR: No matching distribution found for apache-beam[gcp]==2.4.0 (from google-cloud-dataflow)
╭─   debo@pop-os    ~                                                                   1
```
@sparkingdark here `dataflow` is a local module which was wrongly placed before `sys.path.insert` line. As I said [before](https://github.com/pytorch/ignite/issues/1616#issuecomment-774495099) the issue with isort and reordering.
Okay so you are saying that just need to test proper ordering and import can solve this issue. One question if it is an internal module then where can I found this pascal voc example in ignite.
If you ask where this `dataflow` module, it is here : https://github.com/pytorch/ignite/tree/master/examples/references/segmentation/pascal_voc2012/code/dataflow

Yes, minimal fix is just manually reorder imports as it was previously and add something to isort such that it would not reorder in the bad way. Perfect fix is definitely, to add a minimal test of this ref example.
Thanks I will try to reproduce it.

On Wed, Feb 10, 2021, 20:15 vfdev <notifications@github.com> wrote:

> If you ask where this dataflow module, it is here :
> https://github.com/pytorch/ignite/tree/master/examples/references/segmentation/pascal_voc2012/code/dataflow
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <https://github.com/pytorch/ignite/issues/1616#issuecomment-776756129>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AL7XHCCN5NXMLARSB42BSDLS6KLX7ANCNFSM4XFTJCAA>
> .
>

I try to reproduce the issue install the miniconda for this purpose,after that created a file containing the following code 

```python3
import torch
from apex import amp
from code.dataflow.datasets import VOCSegmentationOpencv  # <---- imported before sys.path.insert
from py_config_runner.config_utils import TRAINVAL_CONFIG, assert_config, get_params
from py_config_runner.utils import set_seed
from code.utils import exp_tracking  # <---- imported before sys.path.insert
from code.utils.handlers import predictions_gt_images_handler  # <---- imported before sys.path.insert

# Adds "code" folder to python path
sys.path.insert(0, Path(__file__).parent.parent.as_posix())
```
This is error I got...
```
╰─ /home/debo/miniconda3/bin/python /home/debo/ignite/examples/references/segmentation/pascal_voc2012/vcc.py
Traceback (most recent call last):
  File "/home/debo/ignite/examples/references/segmentation/pascal_voc2012/vcc.py", line 6, in <module>
    from code.utils import exp_tracking  # <---- imported before sys.path.insert
  File "/home/debo/ignite/examples/references/segmentation/pascal_voc2012/code/utils/exp_tracking.py", line 9, in <module>
    import ignite.distributed as idist
ModuleNotFoundError: No module named 'ignite.distributed'
╭─   debo@pop-os    ~/ignite     testing                              1 ↵  3.94G    2.35    14:26:21   
╰─ 
```
Looks like you have installed an old version. Try to install the latest one: 0.4.3
ignite==0.4.3
This is strange. Probably, something odd with your env setup. Try simply: `python -c "import ignite; print(ignite.__version__); import ignite.distributed"`
I checkout the branch 0.4.3 and installed that.after that I got the setup error for pascal voc data 

```
Traceback (most recent call last):
  File "vcc.py", line 7, in <module>
    from code.utils import exp_tracking  # <---- imported before sys.path.insert
  File "/home/debo/ignite/examples/references/segmentation/pascal_voc2012/code/utils/exp_tracking.py", line 144, in <module>
    raise RuntimeError(
RuntimeError: No experiment tracking system is setup. Please, setup either MLflow, Polyaxon or ClearML. For more details see NOTES_*.md
```
probably error solved with bad import.I am doenloading the data.
```python
from pathlib import  Path
import sys
import torch
from apex import amp
from code.dataflow.datasets import VOCSegmentationOpencv  # <---- imported before sys.path.insert
from py_config_runner.config_utils import TRAINVAL_CONFIG, assert_config, get_params
from py_config_runner.utils import set_seed
from code.utils import exp_tracking  # <---- imported before sys.path.insert
from code.utils.handlers import predictions_gt_images_handler  # <---- imported before sys.path.insert

# Adds "code" folder to python path
sys.path.insert(0, Path(__file__).parent.parent.as_posix())
print("executed")
```

run succesfully. @vfdev-5 

instead of using sys.path I use pathlib.Path for that and 

```
╭─   debo@pop-os    ~/ignite/examples/references/segmentation/pascal_voc2012     testing      
╰─ /home/debo/miniconda3/bin/python /home/debo/ignite/examples/references/segmentation/pascal_voc2012/vcc.py
executed
╭─   debo@pop-os    ~/ignite/examples/references/segmentation/pascal_voc2012     testing      
╰─ 
```

what to do next?
I'm not sure if preprending `code.` is the correct solution. To ensure that you have to run the training as it is described in for example in `NOTES_MLflow.md` where `mlflow run` cmd line tool is used. Same for `NOTES_ClearML.md`...

As I said previously, we have to revert the order done by #1605 and put instructions to isort to prevent it from rearranging local modules.
I don't imported code in path ,how can I do that `export what to put = codes path`, i don't understand that's why . I used clearml as per notes.
@sparkingdark if you'd like to help with a fix for this issue, please follow the guideline above. Thanks.
Okay

Resolving patch:
diff --git a/examples/references/segmentation/pascal_voc2012/code/scripts/training.py b/examples/references/segmentation/pascal_voc2012/code/scripts/training.py
--- a/examples/references/segmentation/pascal_voc2012/code/scripts/training.py
+++ b/examples/references/segmentation/pascal_voc2012/code/scripts/training.py
@@ -1,12 +1,14 @@
 # This a training script launched with py_config_runner
 # It should obligatory contain `run(config, **kwargs)` method
-
 import sys
 from collections.abc import Mapping
 from pathlib import Path
 
 import torch
 from apex import amp
+
+# Adds "code" folder to python path
+sys.path.insert(0, Path(__file__).parent.parent.as_posix())
 from dataflow.datasets import VOCSegmentationOpencv
 from py_config_runner.config_utils import TRAINVAL_CONFIG, assert_config, get_params
 from py_config_runner.utils import set_seed
@@ -21,9 +23,6 @@
 from ignite.metrics import ConfusionMatrix, IoU, mIoU
 from ignite.utils import setup_logger
 
-# Adds "code" folder to python path
-sys.path.insert(0, Path(__file__).parent.parent.as_posix())
-
 
 def initialize(config):
 


Test patch: