'AttributeError: module 'keras.utils' has no attribute 'get_file'

When I'm trying to implement the following code

from keras_segmentation.models.segnet import resnet50_segnet
from keras_segmentation.predict import model_from_checkpoint_path

model = resnet50_segnet(n_classes=2 ,  input_height=1440, input_width=1088)

I get this error enter image description here

AttributeError                            Traceback (most recent call last)
<ipython-input-36-da4c2ac2af79> in <module>
  2 from keras_segmentation.predict import model_from_checkpoint_path
  3 
----> 4 model = resnet50_segnet(n_classes=2 ,  input_height=1088, input_width=1440)

 ~/anaconda3/envs/py38/lib/python3.8/site-packages/keras_segmentation/models/segnet.py in resnet50_segnet(n_classes, input_height, input_width, encoder_level)
 74                     encoder_level=3):
 75 
---> 76     model = _segnet(n_classes, get_resnet50_encoder, input_height=input_height,
 77                     input_width=input_width, encoder_level=encoder_level)
 78     model.model_name = "resnet50_segnet"

 ~/anaconda3/envs/py38/lib/python3.8/site-packages/keras_segmentation/models/segnet.py in 
 _segnet(n_classes, encoder, input_height, input_width, encoder_level)
 45             encoder_level=3):
 46 
 ---> 47     img_input, levels = encoder(
 48         input_height=input_height,  input_width=input_width)
 49 

 ~/anaconda3/envs/py38/lib/python3.8/site-packages/keras_segmentation/models/resnet50.py in 
 get_resnet50_encoder(input_height, input_width, pretrained, include_top, weights, 
 input_tensor, input_shape, pooling, classes)
178 
179     if pretrained == 'imagenet':
--> 180         weights_path = keras.utils.get_file(
181             pretrained_url.split("/")[-1], pretrained_url)
182         Model(img_input, x).load_weights(weights_path)

 AttributeError: module 'keras.utils' has no attribute 'get_file'

I'm not quite sure as to how I could possibly solve this error. I'd appreciate receiving some help. Thanks!



Solution 1:[1]

Go the file reporting the error (like ~/anaconda3/envs/py38/lib/python3.8/site-packages/keras_segmentation/models/resnet50.py)

and change:

import keras

to

import tensorflow.keras as keras

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 Youcef4k