Repository: pytorch/vision
Pull request: Making root parameter optional for Vision Dataset
This resolves #8123 while maintaining backward compatibility

cc @vfdev-5

Problem statement:
`VisionDataset` abstract class forces to set 'root' parameter, even if it is unused
### 🐛 Describe the bug

`TypeError: __init__() missing 1 required positional argument: 'root'`

when initializing VisionDataset without `root` param.

```python

from torchvision.transforms import ToTensor
from torchvision.datasets import VisionDataset

class ExtendedVisionDataset(VisionDataset):
  def __init__(self, **kwargs):
    super().__init__(**kwargs)  

transforms = ToTensor()
dataset =ExtendedVisionDataset(transforms =transforms)  # I dont really need root param
```

### Versions

```
PyTorch version: 2.0.0
Is debug build: False
CUDA used to build PyTorch: 11.7
ROCM used to build PyTorch: N/A

OS: Ubuntu 18.04.3 LTS (x86_64)
GCC version: (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0
Clang version: Could not collect
CMake version: version 3.10.2
Libc version: glibc-2.27

Python version: 3.9.18 (main, Sep 11 2023, 13:41:44)  [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-5.15.0-88-generic-x86_64-with-glibc2.27
Is CUDA available: True
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: 
GPU 0: Tesla V100-DGXS-32GB
GPU 1: Tesla V100-DGXS-32GB
GPU 2: Tesla V100-DGXS-32GB
GPU 3: Tesla V100-DGXS-32GB

Nvidia driver version: 515.105.01
cuDNN version: /usr/lib/x86_64-linux-gnu/libcudnn.so.7.6.3
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture:        x86_64
CPU op-mode(s):      32-bit, 64-bit
Byte Order:          Little Endian
CPU(s):              40
On-line CPU(s) list: 0-39
Thread(s) per core:  2
Core(s) per socket:  20
Socket(s):           1
NUMA node(s):        1
Vendor ID:           GenuineIntel
CPU family:          6
Model:               79
Model name:          Intel(R) Xeon(R) CPU E5-2698 v4 @ 2.20GHz
Stepping:            1
CPU MHz:             2468.528
CPU max MHz:         3600.0000
CPU min MHz:         1200.0000
BogoMIPS:            4397.69
L1d cache:           32K
L1i cache:           32K
L2 cache:            256K
L3 cache:            51200K
NUMA node0 CPU(s):   0-39
Flags:               fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 ds_cpl smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 cdp_l3 invpcid_single pti intel_ppin ssbd ibrs ibpb stibp fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm rdt_a rdseed adx smap intel_pt xsaveopt cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts md_clear flush_l1d

Versions of relevant libraries:
[pip3] numpy==1.24.4
[pip3] torch==2.0.0
[pip3] torchmetrics==0.10.3
[pip3] torchvision==0.15.0
[pip3] triton==2.0.0
[conda] blas                      1.0                         mkl  
[conda] mkl                       2023.1.0         h213fc3f_46344  
[conda] mkl-service               2.4.0            py39h5eee18b_1  
[conda] mkl_fft                   1.3.8            py39h5eee18b_0  
[conda] mkl_random                1.2.4            py39hdb19cb5_0  
[conda] numpy                     1.24.4                   pypi_0    pypi
[conda] pytorch                   2.0.0           py3.9_cuda11.7_cudnn8.5.0_0    pytorch
[conda] pytorch-cuda              11.7                 h778d358_5    pytorch
[conda] pytorch-mutex             1.0                        cuda    pytorch
[conda] torchmetrics              0.10.3             pyhd8ed1ab_0    conda-forge
[conda] torchtriton               2.0.0                      py39    pytorch
[conda] torchvision               0.15.0               py39_cu117    pytorch```

cc @pmeier

Hints from issue discussion:
Just pass `root=None` in that case. That is what we are doing for `datasets.FakeData` as well:

https://github.com/pytorch/vision/blob/4433680aa57439ed684f9854fac3443b76e03c03/torchvision/datasets/fakedata.py#L34

`VisionDataset` will not touch `root` in that case

https://github.com/pytorch/vision/blob/4433680aa57439ed684f9854fac3443b76e03c03/torchvision/datasets/vision.py#L38-L40
@pmeier should we make it `None` by default? This can be a non BC-breaking change.

Commit message: made root vaiable optional for Vision Dataset

Patch to review:
diff --git a/torchvision/datasets/vision.py b/torchvision/datasets/vision.py
index aba19369b64..064b5114a23 100644
--- a/torchvision/datasets/vision.py
+++ b/torchvision/datasets/vision.py
@@ -12,7 +12,7 @@ class VisionDataset(data.Dataset):
     It is necessary to override the ``__getitem__`` and ``__len__`` method.
 
     Args:
-        root (string): Root directory of dataset.
+        root (string, optional): Root directory of dataset.
         transforms (callable, optional): A function/transforms that takes in
             an image and a label and returns the transformed versions of both.
         transform (callable, optional): A function/transform that  takes in an PIL image
@@ -29,7 +29,7 @@ class VisionDataset(data.Dataset):
 
     def __init__(
         self,
-        root: str,
+        root: Optional[str] = None,
         transforms: Optional[Callable] = None,
         transform: Optional[Callable] = None,
         target_transform: Optional[Callable] = None,


Code review comments:
diff_hunk: @@ -12,7 +12,7 @@ class VisionDataset(data.Dataset):
     It is necessary to override the ``__getitem__`` and ``__len__`` method.
 
     Args:
-        root (string): Root directory of dataset.
+        root (string, optional): Root directory of dataset.
path: torchvision/datasets/vision.py
text: @user1:
While we're at it, it might be worth clarify that this parameter is not critical anyway

```suggestion
        root (string, optional): Root directory of dataset. Only used for `__repr__`.
```