cannot import name 'RandomBatchGeoSampler' from 'torchgeo.samplers.batch'
See original GitHub issueOn torchgeo==0.1.0
, the import from torchgeo.samplers import GeoSampler
fails with an ImportError
. Interestingly, re-running the same import immediately after succeeds.
>>> from torchgeo.samplers import GeoSampler
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/shared/ritwik/miniconda3/envs/overwatch/lib/python3.7/site-packages/torchgeo/samplers/__init__.py", line 6, in <module>
from .batch import BatchGeoSampler, RandomBatchGeoSampler
File "/shared/ritwik/miniconda3/envs/overwatch/lib/python3.7/site-packages/torchgeo/samplers/batch.py", line 12, in <module>
from torchgeo.datasets.geo import GeoDataset
File "/shared/ritwik/miniconda3/envs/overwatch/lib/python3.7/site-packages/torchgeo/datasets/__init__.py", line 11, in <module>
from .chesapeake import (
File "/shared/ritwik/miniconda3/envs/overwatch/lib/python3.7/site-packages/torchgeo/datasets/chesapeake.py", line 26, in <module>
from ..samplers.batch import RandomBatchGeoSampler
ImportError: cannot import name 'RandomBatchGeoSampler' from 'torchgeo.samplers.batch' (/shared/ritwik/miniconda3/envs/overwatch/lib/python3.7/site-packages/torchgeo/samplers/batch.py)
>>> GeoSampler
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'GeoSampler' is not defined
>>> from torchgeo.samplers import GeoSampler
>>> GeoSampler
<class 'torchgeo.samplers.GeoSampler'>
>>>
Issue Analytics
- State:
- Created 2 years ago
- Comments:5
Top Results From Across the Web
torchgeo.samplers - Read the Docs
This data loader will return 256x256 px images, and has a batch size of 128 and an epoch length of 10,000. Random Batch...
Read more >"ImportError: cannot import name 'BatchSampler'" - Part 1 (2018)
The error I'm getting is “ImportError: cannot import name 'BatchSampler'” – I have searched on google/on the forums, but can't find anybody ...
Read more >torchgeo - PyPI
TorchGeo is a PyTorch domain library, similar to torchvision, providing datasets, samplers, transforms, and pre-trained models specific to geospatial data.
Read more >TorchGeo of PyTorch - E2E Networks
The torchgeo package consists of popular datasets, ... Data samplers appropriate for geospatial data. ... Random Batch Geo Sampler.
Read more >TorchGeo of PyTorch - LinkedIn
The torchgeo package consists of popular datasets, ... Data samplers appropriate for geospatial data. ... Random Batch Geo Sampler.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is due to a circular dependency. Importing
GeoSampler
requires importingGeoDataset
which in turn imports all datasets (includingchesapeake.py
which requiredRadomBatchGeoSampler
). This was resolved post0.1.0
by b67c711 which imports the datasets in torchgeo’s__init__.py
to ensure it’s imported first.In your case, I guess it worked the second time because by then the datasets submodule was already imported by the previous failed call.
The original issue reported in this issue (circular import errors) has been fixed in the new 0.1.1 release, so I’ll close this PR.
I do still want to think about ways to speed up imports, but that can happen later.