image-segmentation-keras icon indicating copy to clipboard operation
image-segmentation-keras copied to clipboard

Error when using segmentation-keras

Open graham-eisele opened this issue 4 years ago • 3 comments

When I run this code

from keras_segmentation.pretrained import pspnet_50_ADE_20K , pspnet_101_cityscapes, pspnet_101_voc12

model = pspnet_101_voc12()

model.train(
    train_images =  "train_images/",
    train_annotations = "train_anno/",
    checkpoints_path="tmp/pspnet_1",
    epochs=5
)

I get this error

graham@graham-desktop:~/Desktop/SimpsonSegmentation$ python3 cartoon.py 
Using TensorFlow backend.
/home/graham/.local/lib/python3.8/site-packages/keras/backend/tensorflow_backend.py:3201: SyntaxWarning: "is" with a literal. Did you mean "=="?
  if training is 1 or training is True:
/home/graham/.local/lib/python3.8/site-packages/keras/backend/tensorflow_backend.py:3207: SyntaxWarning: "is" with a literal. Did you mean "=="?
  elif training is 0 or training is False:
2021-01-30 12:55:09.135892: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.11.0
Traceback (most recent call last):
  File "cartoon.py", line 5, in <module>
    model = pspnet_101_voc12()
  File "/home/graham/.local/lib/python3.8/site-packages/keras_segmentation/pretrained.py", line 80, in pspnet_101_voc12
    return model_from_checkpoint_path(model_config, latest_weights)
  File "/home/graham/.local/lib/python3.8/site-packages/keras_segmentation/pretrained.py", line 8, in model_from_checkpoint_path
    model = model_from_name[model_config['model_class']](
  File "/home/graham/.local/lib/python3.8/site-packages/keras_segmentation/models/pspnet.py", line 120, in pspnet_101
    model = _build_pspnet(nb_classes=nb_classes,
  File "/home/graham/.local/lib/python3.8/site-packages/keras_segmentation/models/_pspnet_2.py", line 266, in _build_pspnet
    res = ResNet(inp, layers=resnet_layers)
  File "/home/graham/.local/lib/python3.8/site-packages/keras_segmentation/models/_pspnet_2.py", line 149, in ResNet
    cnv1 = Conv2D(64, (3, 3), strides=(2, 2), padding='same', name=names[0],
  File "/home/graham/.local/lib/python3.8/site-packages/keras/backend/tensorflow_backend.py", line 75, in symbolic_fn_wrapper
    return func(*args, **kwargs)
  File "/home/graham/.local/lib/python3.8/site-packages/keras/engine/base_layer.py", line 446, in __call__
    self.assert_input_compatibility(inputs)
  File "/home/graham/.local/lib/python3.8/site-packages/keras/engine/base_layer.py", line 310, in assert_input_compatibility
    K.is_keras_tensor(x)
  File "/home/graham/.local/lib/python3.8/site-packages/keras/backend/tensorflow_backend.py", line 695, in is_keras_tensor
    if not is_tensor(x):
  File "/home/graham/.local/lib/python3.8/site-packages/keras/backend/tensorflow_backend.py", line 703, in is_tensor
    return isinstance(x, tf_ops._TensorLike) or tf_ops.is_dense_tensor_like(x)
AttributeError: module 'tensorflow.python.framework.ops' has no attribute '_TensorLike'

I am using python3.8, tensorflow 2.4.1, keras 2.3.1, and keras segmentation 0.3.0. I am also using Ubuntu 20.04 for OS.

graham-eisele avatar Jan 30 '21 19:01 graham-eisele

Could you try it on google colab? That will help us pinpoint the problem

On Sat, Jan 30, 2021 at 2:01 PM DerpyMan101 [email protected] wrote:

When I run this code

`from keras_segmentation.pretrained import pspnet_50_ADE_20K , pspnet_101_cityscapes, pspnet_101_voc12

model = pspnet_101_voc12()

model.train( train_images = "train_images/", train_annotations = "train_anno/", checkpoints_path="tmp/pspnet_1", epochs=5 )

I get this error

``graham@graham-desktop:~/Desktop/SimpsonSegmentation$ python3 cartoon.py Using TensorFlow backend. /home/graham/.local/lib/python3.8/site-packages/keras/backend/tensorflow_backend.py:3201: SyntaxWarning: "is" with a literal. Did you mean "=="? if training is 1 or training is True: /home/graham/.local/lib/python3.8/site-packages/keras/backend/tensorflow_backend.py:3207: SyntaxWarning: "is" with a literal. Did you mean "=="? elif training is 0 or training is False: 2021-01-30 12:55:09.135892: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.11.0 Traceback (most recent call last): File "cartoon.py", line 5, in model = pspnet_101_voc12() File "/home/graham/.local/lib/python3.8/site-packages/keras_segmentation/pretrained.py", line 80, in pspnet_101_voc12 return model_from_checkpoint_path(model_config, latest_weights) File "/home/graham/.local/lib/python3.8/site-packages/keras_segmentation/pretrained.py", line 8, in model_from_checkpoint_path model = model_from_name[model_config['model_class']]( File "/home/graham/.local/lib/python3.8/site-packages/keras_segmentation/models/pspnet.py", line 120, in pspnet_101 model = _build_pspnet(nb_classes=nb_classes, File "/home/graham/.local/lib/python3.8/site-packages/keras_segmentation/models/_pspnet_2.py", line 266, in _build_pspnet res = ResNet(inp, layers=resnet_layers) File "/home/graham/.local/lib/python3.8/site-packages/keras_segmentation/models/_pspnet_2.py", line 149, in ResNet cnv1 = Conv2D(64, (3, 3), strides=(2, 2), padding='same', name=names[0], File "/home/graham/.local/lib/python3.8/site-packages/keras/backend/tensorflow_backend.py", line 75, in symbolic_fn_wrapper return func(*args, **kwargs) File "/home/graham/.local/lib/python3.8/site-packages/keras/engine/base_layer.py", line 446, in call self.assert_input_compatibility(inputs) File "/home/graham/.local/lib/python3.8/site-packages/keras/engine/base_layer.py", line 310, in assert_input_compatibility K.is_keras_tensor(x) File "/home/graham/.local/lib/python3.8/site-packages/keras/backend/tensorflow_backend.py", line 695, in is_keras_tensor if not is_tensor(x): File "/home/graham/.local/lib/python3.8/site-packages/keras/backend/tensorflow_backend.py", line 703, in is_tensor return isinstance(x, tf_ops._TensorLike) or tf_ops.is_dense_tensor_like(x) AttributeError: module 'tensorflow.python.framework.ops' has no attribute '_TensorLike'

I am using python3.8, tensorflow 2.4.1, keras 2.3.1, and keras segmentation 0.3.0. I am also using Ubuntu 20.04 for OS.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/divamgupta/image-segmentation-keras/issues/266, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAONR5LWMAPYWU2C47JEZJDS4RJPXANCNFSM4W2SD5MA .

divamgupta avatar Jan 30 '21 19:01 divamgupta

I was able to fix the problem after following this: https://github.com/tensorflow/tensorflow/issues/38589#issuecomment-735540130

but now I get his error:

Traceback (most recent call last):
  File "cartoon.py", line 8, in <module>
    model.train(
  File "/home/graham/.local/lib/python3.8/site-packages/keras_segmentation/train.py", line 107, in train
    with open(checkpoints_path+"_config.json", "w") as f:
FileNotFoundError: [Errno 2] No such file or directory: 'tmp/pspnet_1_config.json'

graham-eisele avatar Jan 30 '21 20:01 graham-eisele

I solved this by creating a tmp folder, and successfully trained the model, but when I try to test I get

 File "/home/graham/.local/lib/python3.8/site-packages/keras_segmentation/predict.py", line 24, in model_from_checkpoint_path
    assert (os.path.isfile(checkpoints_path+"_config.json")
AssertionError: Checkpoint not found.

graham-eisele avatar Jan 30 '21 21:01 graham-eisele