'TypeError: 'ZipFile' object is not callable
I am trying to save the new cropped brain tumor images into the subfolders of TRAIN_CROP, TEST_CROP, and VAL_CROP in the main folder of TRAIN, TEST, and VAL. x_set and y_set each contains the images which I want to separate in 'YES' and 'NO'.
def save_new_images(x_set, y_set, folder_name):
i = 0
for (img, imclass) in zip(x_set, y_set): <---showing error here
if imclass == 0:
cv2.imwrite(folder_name+'NO/'+str(i)+'.jpg', img)
else:
cv2.imwrite(folder_name+'YES/'+str(i)+'.jpg', img)
i += 1
># saving new images to the folder
!mkdir TRAIN_CROP TEST_CROP VAL_CROP TRAIN_CROP/YES TRAIN_CROP/NO TEST_CROP/YES TEST_CROP/NO VAL_CROP/YES VAL_CROP/NO
save_new_images(X_train_crop, y_train, folder_name='TRAIN_CROP/')
save_new_images(X_val_crop, y_val, folder_name='VAL_CROP/')
save_new_images(X_test_crop, y_test, folder_name='TEST_CROP/')```
Solution 1:[1]
This means that you somehow shadow the zip
builtin with ZipFile
.
One possible reason would be that you have an import like:
from zipfile import ZipFile as zip
In that case use a different alias.
Another possibility would be that you do a *-import (from somemodule import *
) which does the same.
Solution 2:[2]
I have faced the same problem, the case is solved by writing
from zipfile import ZipFile as zipfile
Actually the ZipFile
is the module within zipfile
class.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | mata |
Solution 2 | Tyler2P |