Closed bryanwong17 closed 1 year ago
How did you install it? And what OS and Python version are you on? It sound like an incorrect installation.
Hi @manthey, My operating system is Windows, and I have tried both Python 3.7 and Python 3.10. What should I use? Is there a requirement.txt file you could share?
It should work (with some sources) on Python3.6+ on Windows. For instance, on a clean Windows 10 with Python 3.10, I just did "pip install large-image[pil]", which installs the base library and the pil tile source, and it works fine. For many tile sources, you need the appropriate binary library installed (e.g., openslide or GDAL). There is a conda forge installation which has some of these.
All of the tile sources work on linux; not all of them have Windows-compatible binaries (e.g., I don't know if the mapnik or vips sources can work on windows).
Hi @manthey , I reinstalled it again with "pip-install large-image[pil]" and the error was like this:
File "C:\self-learning-transformer-mil\src\preprocessing\extract_patches.py", line 10, in
OSError: [WinError 127] The specified procedure could not be found
Do you have any suggestions for what I should do?
open_slide_path = "C:/openslide-win64-20221111" os.add_dll_directory(os.path.join(open_slide_path, 'bin'))
I added the above code and below was the error:
File "C:\self-learning-transformer-mil\src\preprocessing\extract_patches.py", line 211, in
raise TileSourceException('No available tilesource for %s' % pathOrUri)
large_image.exceptions.TileSourceException: No available tilesource for E:/CAMELYON16/images_train\normal_001.tif
What is the correct way to add openslide dll path?
I want to extract the patches of CAMELYON16 (.tif format). Is that available on windows?
Since you're on windows and using conda
as your environment/package manager, you should try to install the dependencies like open slide through conda to get the binaries/dlls.
openslide
as you initially installed with pip
, and this will likely conflict if trying to install it with conda
: pip uninstall openslide-python
conda install -c conda-forge openslide-python
. This will install openslide
too which will have the DLLsHope this helps!
FWIW, a few of the large-image
source modules are published on conda-forge
(mostly for geospatial applications). We probably want to consider add more of the source modules for use cases like this so that you can fully install with conda
and not have a mix of conda
and pip
installed packages
Hi @banesullivan, thanks for the suggestions. I have already uninstalled openslide using pip and reinstalled it through conda. It seems like the error now is "No module named openslide" and below is the output when installing openslide through conda (It says openslide-python isn't available from current channels).
Collecting package metadata (current_repodata.json): done Solving environment: failed with initial frozen solve. Retrying with flexible solve. Collecting package metadata (repodata.json): done Solving environment: failed with initial frozen solve. Retrying with flexible solve.
PackagesNotFoundError: The following packages are not available from current channels:
Current channels:
To search for alternate channels that may provide the conda package you're looking for, navigate to
https://anaconda.org
and use the search bar at the top of the page.
You need to specify the conda-forge channel
conda install -c conda-forge openslide-python
Hi @banesullivan, I already followed your suggestion to install openslide-python through conda with the below command:
conda install -c conda-forge openslide-python
However, I still received an error below:
PackagesNotFoundError: The following packages are not available from current channels:
Do you have any ideas?
Ah my bad. It looks like the open slide package (open slide-pythons dependency) doesn't build for windows: https://anaconda.org/conda-forge/openslide/files
I'm not too sure where to go from here
Perhaps we can accomplish what you're after without open slide... let me read back in the issue on what you're trying to do
No worries. If you have any suggestions for how to resolve this issue, please let me know. Thanks
So what exactly are you trying to do? I'm confused by what you mean by "patches"
Can you share the image file you're working with?
Hi @banesullivan, I am trying to extract patches of the CAMELYON16 dataset (.tif format)
Would you please elaborate on what you mean by "patches"? Would you provide an example of what you are trying to do?
In the context of whole slide imaging, a patch is a small portion or subset of the entire slide image. Whole slide images are extremely large digital images that are used to represent and analyze tissue samples in pathology. These images can be several gigabytes in size and contain millions of pixels.
To manage the large size of these images, they are often divided into smaller patches, which can be more easily processed and analyzed. Patch-based analysis is a common method used in digital pathology to extract features or perform tasks on the tissue sample.
FYI, I followed this code for extracting the patches:
An example of extracted patches dataset:
Ah, thank you for clarifying! I don't come from the pathology or medical imaging world so I'm not used to the vocabulary.
I'm interpreting patch to be the same thing as a "region" and thus want to point you to large-image's getRegion()
method: https://girder.github.io/large_image/_build/large_image/large_image.tilesource.html#large_image.tilesource.base.TileSource.getRegion
FYI, I followed this code for extracting the patches: https://github.com/gokberkgul/self-learning-transformer-mil/blob/main/src/preprocessing/extract_patches.py
Is this code giving you the original error you posted above?:
AttributeError: module 'large_image' has no attribute 'getTileSource'
If so, I suspect your Python environment is corrupted (dependencies not installed safely/correctly) or that you have a folder called large_image
in your PYTHONPATH that is being imported instead of the actual large_image
module.
Can you open Python and verify:
>>> import large_image
>>> large_image.__file__
...
>>> help(large_image.getTileSource)
Have you tried reaching out to @gokberkgul about their usage of large-image in that script you shared?
Here is the output of what you requested. I haven't received his reply back and I thought the problem was from the large_image library
import large_image large_image.file 'C:\Users\user\anaconda3\envs\hipt\lib\site-packages\large_image\init.py'
help(large_image.getTileSource) Help on function getTileSource in module large_image.tilesource:
getTileSource(*args, **kwargs) Get a tilesource using the known sources. If tile sources have not yet been loaded, load them.
:returns: A tilesource for the passed arguments.
And so now when you run that script, you get the DLL issues?
I don't think I get DLL issues, but instead, the error looks like this:
File "C:\self-learning-transformer-mil\src\preprocessing\extract_patches.py", line 211, in main(args) File "C:\self-learning-transformer-mil\src\preprocessing\extract_patches.py", line 195, in main tile_slide(slide_path, out_folder, args.size, overlap, args.magnification, args.tissue_threshold, thresholds) File "C:\self-learning-transformer-mil\src\preprocessing\extract_patches.py", line 115, in tile_slide ts = large_image.getTileSource(slide_path) File "C:\Users\user\anaconda3\envs\hipt\lib\site-packages\large_image\tilesource_init.py", line 79, in getTileSource return getTileSourceFromDict(AvailableTileSources, *args, **kwargs) File "C:\Users\user\anaconda3\envs\hipt\lib\site-packages\large_image\tilesource_init.py", line 67, in getTileSourceFromDict raise TileSourceException('No available tilesource for %s' % pathOrUri) large_image.exceptions.TileSourceException: No available tilesource for E:/CAMELYON16/images_train\normal_001.tif
Can you try installing large-image-source-tiff
from conda-forge and then running the script?:
conda install -c large-image-source-tiff
This is what I get:
CondaValueError: too few arguments, must supply command line package specs or --file
Sorry, late at night here. I meant to add the conda-forge channel:
conda install -c conda-forge large-image-source-tiff
large_image.exceptions.TileSourceException: No available tilesource for E:/CAMELYON16/images_train\normal_001.tif
Are you sure that you have the normal_001.tif file in the specified path? Since you are using my code, and I have my work-related stuff in E: drive, I just wanted to make sure that you have the same setup.
Hi @gokberkgul ,Yes, I'm pretty sure. You can check the below screenshot. Do I miss something?
Traceback (most recent call last): File "C:\self-learning-transformer-mil\src\preprocessing\extract_patches.py", line 10, in from openslide import open_slide File "C:\Users\user\anaconda3\envs\hipt\lib\site-packages\openslideinit.py", line 30, in from openslide import lowlevel File "C:\Users\user\anaconda3\envs\hipt\lib\site-packages\openslide\lowlevel.py", line 55, in lib = cdll.LoadLibrary('libopenslide-0.dll') File "C:\Users\user\anaconda3\envs\hipt\lib\ctypes_init.py", line 452, in LoadLibrary return self.dlltype(name) File "C:\Users\user\anaconda3\envs\hipt\lib\ctypes_init.py", line 374, in init self._handle = _dlopen(self._name, mode) OSError: [WinError 127] The specified procedure could not be found
Maybe try adding the dll path to the sys in the beginning of the script?
import sys
sys.path.insert(0,'/path/to/dll')
Hi @gokberkgul , actually I already solved the open slide issue. The only remaining is large-image ("No available tilesource")
Hm. I'm able to read this with the large-image-source-gdal
module but not the tiff module:
@manthey, any ideas what's going wrong here:
>>> import large_image_source_tiff
>>> large_image_source_tiff.open('~/Downloads/normal_152.tif')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/bane.sullivan/Software/girder/large_image/sources/tiff/large_image_source_tiff/__init__.py", line 741, in open
return TiffFileTileSource(*args, **kwargs)
File "/Users/bane.sullivan/Software/girder/large_image/large_image/cache_util/cache.py", line 216, in __call__
raise exc
File "/Users/bane.sullivan/Software/girder/large_image/large_image/cache_util/cache.py", line 209, in __call__
instance = super().__call__(*args, **kwargs)
File "/Users/bane.sullivan/Software/girder/large_image/sources/tiff/large_image_source_tiff/__init__.py", line 106, in __init__
alldir = self._scanDirectories()
File "/Users/bane.sullivan/Software/girder/large_image/sources/tiff/large_image_source_tiff/__init__.py", line 190, in _scanDirectories
dir = TiledTiffDirectory(self._largeImagePath, directoryNum, validate=False)
File "/Users/bane.sullivan/Software/girder/large_image/sources/tiff/large_image_source_tiff/tiff_reader.py", line 146, in __init__
self._loadMetadata()
File "/Users/bane.sullivan/Software/girder/large_image/sources/tiff/large_image_source_tiff/tiff_reader.py", line 306, in _loadMetadata
value = self._tiffFile.GetField(field)
File "/opt/miniconda3/envs/geospatial/lib/python3.9/site-packages/libtiff/libtiff_ctypes.py", line 1417, in GetField
return convert(data)
File "/opt/miniconda3/envs/geospatial/lib/python3.9/site-packages/libtiff/libtiff_ctypes.py", line 384, in <lambda>
ctypes.POINTER(ctypes.c_uint32), lambda _d: _d.contents),
ValueError: NULL pointer access
@bryanwong17, could you try install the GDAL module:
conda install -c conda-forge large-image-source-gdal
Then running your script? This isn't the most ideal, but it may work for you.
I changed different env and there was an error when importing "large_image_source_tiff"
Hi @banesullivan @gokberkgul @manthey ,thanks for helping me. The code now runs perfectly on my computer after installing WSL: Ubuntu version and making new env there
I tried extracting the patches using your code. However, I received the following error message:
AttributeError: module 'large_image' has no attribute 'getTileSource'
Do you have any idea why this happens? Thank you!