SyntaxError: invalid syntax when using the retina net library

397 Views Asked by At

i am trying to load a model using the models.load_model() api but i keep getting this error. I tried installing all the necessary keras and tensorflow library but it doesnot seem to work.

This is my current code

import numpy as np
import matplotlib.pyplot as plt
import requests
import urllib
import os
from PIL import Image

from keras_retinanet import models
from keras_retinanet.utils.image import preprocess_image, resize_image
from keras_retinanet.utils.visualization import draw_box, draw_caption
from keras_retinanet.utils.colors import label_color

# https://github.com/fizyr/keras-retinanet/releases
# urllib.urlretrieve('https://github.com/fizyr/keras-retinanet/releases/download/0.5.1/resnet50_coco_best_v2.1.0.h5',
#     'pretrained_model.h5')
# retrieving the model
model = models.load_model('pretrained_model.h5')

class_names = [l.rstrip() for l in open('coco_categories.txt')]
print(class_name)

    Traceback (most recent call last):
      File "Retinet_pretrained.py", line 18, in <module>
        model = models.load_model('pretrained_model.h5')
      File "/home/./.local/lib/python2.7/site-packages/keras_retinanet/models/__init__.py", line 87, in load_model
        return keras.models.load_model(filepath, custom_objects=backbone(backbone_name).custom_objects)
      File "/home/./.local/lib/python2.7/site-packages/keras_retinanet/models/__init__.py", line 57, in backbone
        from .resnet import ResNetBackbone as b
      File "/home/./.local/lib/python2.7/site-packages/keras_retinanet/models/resnet.py", line 21, in <module>
        from . import retinanet
      File "/home/./.local/lib/python2.7/site-packages/keras_retinanet/models/retinanet.py", line 19, in <module>
        from .. import layers
      File "/home/./.local/lib/python2.7/site-packages/keras_retinanet/layers/__init__.py", line 1, in <module>
        from ._misc import RegressBoxes, UpsampleLike, Anchors, ClipBoxes  # noqa: F401
      File "/home/./.local/lib/python2.7/site-packages/keras_retinanet/layers/_misc.py", line 19, in <module>
        from .. import backend
      File "/home/./.local/lib/python2.7/site-packages/keras_retinanet/backend/__init__.py", line 1, in <module>
        from .backend import *  # noqa: F401,F403
      File "/home/./.local/lib/python2.7/site-packages/keras_retinanet/backend/backend.py", line 100
        return tensorflow.map_fn(*args, **kwargs, fn_output_signature=sig)
                                                ^
    SyntaxError: invalid syntax
0

There are 0 best solutions below