bnsreenu / python_for_microscopists

https://www.youtube.com/channel/UC34rW-HtPJulxr5wp2Xa04w?sub_confirmation=1
MIT License
3.78k stars 2.35k forks source link

AttributeError: module 'keras.backend' has no attribute 'sum' #76

Open aggarwalstuti opened 6 months ago

aggarwalstuti commented 6 months ago

After entering the following code: metrics=['accuracy', jacard_coef]

def get_model(): return multi_unet_model(n_classes=n_classes, IMG_HEIGHT=IMG_HEIGHT, IMG_WIDTH=IMG_WIDTH, IMG_CHANNELS=IMG_CHANNELS)

model = get_model() model.compile(optimizer='adam', loss=total_loss, metrics=metrics)

model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=metrics)

model.summary()

history1 = model.fit(X_train, y_train, batch_size = 16, verbose=1, epochs=100, validation_data=(X_test, y_test), shuffle=False)

I am encountering the following error: Total params: 1,941,190 (7.41 MB) Trainable params: 1,941,190 (7.41 MB) Non-trainable params: 0 (0.00 B) Epoch 1/100

AttributeError Traceback (most recent call last) in <cell line: 12>() 10 11 ---> 12 history1 = model.fit(X_train, y_train, 13 batch_size = 16, 14 verbose=1,

3 frames /usr/local/lib/python3.10/dist-packages/segmentation_models/base/functional.py in f_score(gt, pr, beta, class_weights, class_indexes, smooth, per_image, threshold, *kwargs) 143 144 # calculate score --> 145 tp = backend.sum(gt pr, axis=axes) 146 fp = backend.sum(pr, axis=axes) - tp 147 fn = backend.sum(gt, axis=axes) - tp

AttributeError: module 'keras.backend' has no attribute 'sum'

I am using keras Version: 3.0.2 and for tensorflow Version: 2.15.0.post1

AhabbscienceStudioPak commented 2 months ago

You need to use keras version 2 and an older version of segmentation mask 3d library that supports keras 2.