简体   繁体   中英

'module' object is not callable issue

For some reason I'm getting a module object is not callable error on this code. I am not understanding the reason behind this error? What could be the reason for this error? I looked online and found a common explanation that this could be due to similar module and function names. But I am unable to fix it.

def Dataset_loader(DIR, RESIZE, sigmaX=10):
    IMG = []
    read = lambda imname: np.asarray(Image.open(imname).convert("RGB"))
    for IMAGE_NAME in tqdm(os.listdir(DIR)):
        PATH = os.path.join(DIR,IMAGE_NAME)
        _, ftype = os.path.splitext(PATH)
        if ftype == ".png":
            img = read(PATH)
           
            img = cv2.resize(img, (RESIZE,RESIZE))
           
            IMG.append(np.array(img))
    return IMG

ben_train = np.array(Dataset_loader('D:/regionGrowing_MLT/AllSavedRGBImages/Training/Benign',224))
mal_train = np.array(Dataset_loader('D:/regionGrowing_MLT/AllSavedRGBImages/Training/Malignant',224))
ben_test = np.array(Dataset_loader('D:/regionGrowing_MLT/AllSavedRGBImages/Test/Benign',224))
mal_test = np.array(Dataset_loader('D:/regionGrowing_MLT/AllSavedRGBImages/Test/Malignant',224))

The above code is throwing me the following error message:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-25-0c6ae6585a38> in <module>
     13     return IMG
     14 
---> 15 ben_train = np.array(Dataset_loader('D:/regionGrowing_MLT/AllSavedRGBImages/Training/Benign',224))
     16 mal_train = np.array(Dataset_loader('D:/regionGrowing_MLT/AllSavedRGBImages/Training/Malignant',224))
     17 ben_test = np.array(Dataset_loader('D:/regionGrowing_MLT/AllSavedRGBImages/Test/Benign',224))

<ipython-input-25-0c6ae6585a38> in Dataset_loader(DIR, RESIZE, sigmaX)
      2     IMG = []
      3     read = lambda imname: np.asarray(Image.open(imname).convert("RGB"))
----> 4     for IMAGE_NAME in tqdm(os.listdir(DIR)):
      5         PATH = os.path.join(DIR,IMAGE_NAME)
      6         _, ftype = os.path.splitext(PATH)

~\anaconda3\lib\site-packages\pyforest\_importable.py in __call__(self, *args, **kwargs)
     47     def __call__(self, *args, **kwargs):
     48         self.__maybe_import__()
---> 49         return eval(self.__imported_name__)(*args, **kwargs)
     50 
     51     def __repr__(self, *args, **kwargs):

TypeError: 'module' object is not callable

Any suggestions would be appreciated

You probably have imported tqdm as import tqdm . Now you are trying to call the module in your script. What you have to do is from tqdm import tqdm . Know you are importing the function from the module which have both the same name. It's quite common in python packages and you have to pay attention to it. Alternatively you could also call it like tdqm.tdqm(...) . As then you would explicitly state the module and the function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM