erdogant / clustimage

clustimage is a python package for unsupervised clustering of images.
https://erdogant.github.io/clustimage
Other
92 stars 8 forks source link

can not find or create dirpath under linux #6

Closed cp1972 closed 2 years ago

cp1972 commented 2 years ago

Hello, and thank you for clustimage! Running a little script on a linux box generates the following error:

$ python3.8 clustimg.py [clustimage] >ERROR> [None] does not exists or can not be created. Traceback (most recent call last): File "/home/cpsoz/.local/lib/python3.8/site-packages/clustimage/clustimage.py", line 2554, in _set_tempdir dirpath = os.path.join(tempfile.tempdir, 'clustimage') File "/usr/lib/python3.8/posixpath.py", line 76, in join a = os.fspath(a) TypeError: expected str, bytes or os.PathLike object, not NoneType

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "clustimg.py", line 9, in cl = Clustimage(method='pca',dirpath=None,embedding='tsne',grayscale=False,dim=(128,128),params_pca={'n_components':0.5}) File "/home/cpsoz/.local/lib/python3.8/site-packages/clustimage/clustimage.py", line 208, in init self.params['dirpath'] = _set_tempdir(dirpath) File "/home/cpsoz/.local/lib/python3.8/site-packages/clustimage/clustimage.py", line 2566, in _set_tempdir raise Exception(logger.error('[%s] does not exists or can not be created.', dirpath)) Exception: None

Script clustimg.py has the following content:

import sys import os import glob from clustimage import Clustimage cl = Clustimage(method='pca',dirpath=None,embedding='tsne',grayscale=False,dim=(128,128),params_pca={'n_components':0.5}) in_files = input("""Give the absolute path to a directory with your files: \n""") some_files = glob.glob(in_files) print(some_files) results = cl.fit_transform(some_files, cluster='agglomerative', evaluate='silhouette', metric='euclidean', linkage='ward', min_clust=3, max_clust=8, cluster_space='high')

cl.clusteval.plot() cl.clusteval.scatter(cl.results['xycoord'])

What I have tried: I can run clustimage if I am changing the line 2554 in /home/cpsoz/.local/lib/python3.8/site-packages/clustimage/clustimage.py like this:

dirpath = os.path.join(tempfile.tempdir, 'clustimage') --> dirpath = os.path.join('/home/cpsoz', 'clustimage')

where /home/cpsoz is my user directory. 'tempfile' should default to the user directory if 'dirpath' is None, but it does not. As 'dirpath' is None per default, a workaround could be to prompt the user to enter his own path as 'dirpath'.

Note: replacing

cl = Clustimage(method='pca',dirpath=None,embedding='tsne',grayscale=False,dim=(128,128),params_pca={'n_components':0.5})

with

cl = Clustimage(method='pca',dirpath='/home/cpsoz',embedding='tsne',grayscale=False,dim=(128,128),params_pca={'n_components':0.5})

is producing the same error as mentioned. Best wishes cp

erdogant commented 2 years ago

I created a small update using the absolute path for the temp directory. Can you try again whether it works now? update first with: pip install -U clustimage Version should be >= v1.5.4

from clustimage import Clustimage

cl = Clustimage(method='pca',dirpath=None,embedding='tsne',grayscale=False,dim=(128,128),params_pca={'n_components':0.5})

# load example with flowers
pathnames = cl.import_example(data='flowers')

# Cluster flowers
cl.fit_transform(pathnames)

# Make plot
cl.clusteval.plot()
cl.clusteval.scatter(cl.results['xycoord'])
cp1972 commented 2 years ago

Solved, thank you! gettempdir() did the trick. Best wishes cp

erdogant commented 2 years ago

ah ok! nice!