eve-ning / glcm-cupy Goto Github PK
View Code? Open in Web Editor NEWGLCM in CUDA
License: MIT License
GLCM in CUDA
License: MIT License
Implement an arg to disable
tqdm
Is it worth for this project?
Hello, really great work in implementing this. One question...:
I understand the image shrinks because of the effect of the sliding window on the edges. Wouldn't there be a way around that by padding the original image on its outside dimensions with artificial values (a number not used in the grayscale binning range - let's say 0, while the scale of the image would be (1-16), instead of (0-15). GLCMs rows and columns with 0 would then have to be removed before haralick features calculations.
currently in glcm_cupy/glcm/glcm.py
, we have
from cucim.skimage.util.shape import \
view_as_windows as view_as_windows_cucim
from glcm_cupy.utils import view_as_windows_cp
...
if USE_CUCIM:
ij = view_as_windows_cucim(
im_chn, (self._diameter, self._diameter)
)
else:
ij = view_as_windows_cp(im_chn, (self._diameter, self._diameter))
which may be redundant, if view_as_windows_cucim
does not perform any essential speedup over view_as_windows_cp
.
view_as_windows_cp
is an adaptation of skimage.utils.view_as_windows
, with cp.ndarray
substituting np.ndarray
Hello,
I am facing this error. Error details and my usage are shown below:
g = GLCM(
File "/anaconda/envs/cucim/lib/python3.9/site-packages/glcm_cupy/glcm_base.py", line 107, in run
self.progress = tqdm(total=self.glcm_cells(im),
File "/anaconda/envs/cucim/lib/python3.9/site-packages/glcm_cupy/glcm/glcm.py", line 82, in glcm_cells
return np.prod(self.glcm_shape(im[..., 0])) *
File "/anaconda/envs/cucim/lib/python3.9/site-packages/glcm_cupy/glcm/glcm.py", line 90, in glcm_shape
im_chn.shape[1] - 2 * self.step_size - 2 * self.radius)
IndexError: tuple index out of range
def get_glcm_gpu(patch):
ar = np.asarray(patch)
# g = GLCM(directions=(Direction.EAST, Direction.SOUTH_EAST, Direction.SOUTH,
# Direction.SOUTH_WEST), bin_from=256, bin_to=16).run(patch)
g = GLCM(
directions=(Direction.EAST, Direction.SOUTH_EAST),
bin_from=256, bin_to=16).run(ar)
return g
patch is nothing but a grayscale image of size (50, 50). Please help.
If you calculate GLCM today, it returns all the 6 features implemented.
Most researchers or developers don't need all features calculated and if you have a huge size of images to calculate it could mean a huge memory consumption.
In my case I have a dataset of 2 GB and if I multiply by 6 (number of features), my code needs 8 GB at least to run. (Ok, I know... there are several workarounds for it 😃, but I'm imagining a real time scenario).
This feature request would be interesting because we cal also compare the speedup GLCM calculation with scikit image for each props separately.
Currently tqdm is down for cupy
The main cause is that glcm_cells
returned an cp.ndarray
which tqdm
rejected.
Since it's not necessary that it's an ndarray
(we're expecting an int
), we cast it to int.
Currently trying to implement CI/CD however, there's some trouble with dealing with GitHub Actions' CUDA
https://github.com/Eve-ning/glcm-cupy/runs/7160528149?check_suite_focus=true
E ================================================================
E Failed to import CuPy.
E
E If you installed CuPy via wheels (cupy-cudaXXX or cupy-rocm-X-X), make sure that the package matches with the version of CUDA or ROCm installed.
E
E On Linux, you may need to set LD_LIBRARY_PATH environment variable depending on how you installed CUDA/ROCm.
E On Windows, try setting CUDA_PATH environment variable.
E
E Check the Installation Guide for details:
E https://docs.cupy.dev/en/latest/install.html
E
E Original error:
E ImportError: libcuda.so.1: cannot open shared object file: No such file or directory
E ================================================================
See: #24
normalize_features
should be normalized_features
as they both existglcm
and glcm_cross
should explicitly call signatures. E.g. fn(explicit_arg=arg)
test__from_windows()
fails and is redundanttest_from_2d_image
fails due to missing 3rd dimensiontest_image_tiff
is redundantGLCM._binner
is now binner
in utils
See glcm_cross.py
make_windows
. By uncommenting and using view_as_windows_cp
, the unit tests fail for some reason.
In our case, we have (H, W, C)
as input, we may expand to (B, H, W, C)
B
will act similarly to C
, just that it'll be the dim for separate images instead of channels
I believe this is the best order of ndim as it's similar to syntax of PyTorch
PyTorch uses: (N,Cout,Hout,Wout), however, I feel that C in the 2nd dim doesn't make sense compared to how conventional image loaders order the dimensions. (H, W, C) or (W, H, C)
The example bellow does not work because it expects a numpy data from input. The code should also consider cupy data. Specially for workflows that are handling data directly from GPU.
import cupy as cp
from PIL import Image
# Here, we load in the array
# We divide the image by / 16 as it'll take too long
ar = cp.asarray(Image.open("../../data/image.jpg"))[::4,::4]
# We may use the class variant to run GLCM
from glcm_cupy import GLCM, Direction
g = GLCM(
directions=(Direction.EAST, Direction.SOUTH_EAST),
bin_from=256, bin_to=16).run(ar)
# Alternatively, use the function variant
from glcm_cupy import glcm
g = glcm(ar, bin_from=256, bin_to=16)
# We yield the features using constants defined in conf
from glcm_cupy.conf import CONTRAST, CORRELATION, ASM
print(g[..., CONTRAST])
print(g[..., CORRELATION])
print(g[..., ASM])
# Alternatively, since these constants are simply integers
print(g[..., 0])
print(g[..., 1])
print(g[..., 2])
It returns basically a TypeError
:
TypeError: `arr_in` must be a numpy ndarray
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.