bentoml / BentoML

The easiest way to serve AI apps and models - Build Model Inference APIs, Job queues, LLM apps, Multi-model pipelines, and more!
https://bentoml.com
Apache License 2.0
7.16k stars 792 forks source link

AttributeError: 'Functional' object has no attribute '_make_predict_function' #1308

Closed edwin-19 closed 3 years ago

edwin-19 commented 3 years ago

Describe the bug

When i am trying to save a keras model artifacts i get the following error

AttributeError: 'Functional' object has no attribute '_make_predict_function'

To Reproduce

see screenshot logs

Expected behavior

should be able to save bento model

Screenshots/Logs

# seg_bento_model.py
import bentoml
from bentoml.artifact import KerasModelArtifact
from bentoml.service import BentoService
from bentoml.adapters import FileInput, ImageInput

from utils import utilities
@bentoml.env(pip_dependencies=['tensorflow==2.1', 'opencv-python', 'imutils', 'numpy', 'efficientnet'])
@bentoml.artifacts([KerasModelArtifact('model')])
class SegmentationService(BentoService):
    @bentoml.api(input=ImageInput(), batch=True)
    def predict(self, images):
        # preprocess
        pre_processed_images = utilities.pre_process(images)

        print(self.artifacts.seg_model)
        preds = self.artifacts.seg_model.predict(pre_processed_images)

        points = utilities.post_process(preds)

        return points

# save_bentoml_model.py
import tensorflow as tf
import efficientnet.tfkeras

from seg_bento_model import SegmentationService
if __name__ == "__main__":
    model = tf.keras.models.load_model('model/model.h5', compile=False)

    seg_bento_svc = SegmentationService()
    seg_bento_svc.pack('seg_model', model)
    seg_bento_svc.save()
python save_bentoml_model.py

Traceback (most recent call last):
  File "save_bento_model.py", line 10, in <module>
    seg_bento_svc.pack('seg_model', seg_model)
  File "/home/wise/anaconda3/envs/py37tf21/lib/python3.7/site-packages/bentoml/service/__init__.py", line 689, in pack
    self.artifacts.get(name).pack(*args, **kwargs)
  File "/home/wise/anaconda3/envs/py37tf21/lib/python3.7/site-packages/bentoml/service/artifacts/__init__.py", line 108, in wrapped_pack
    ret = original(*args, **kwargs)
  File "/home/wise/anaconda3/envs/py37tf21/lib/python3.7/site-packages/bentoml/frameworks/keras.py", line 176, in pack
    model._make_predict_function()
AttributeError: 'Functional' object has no attribute '_make_predict_function'

Environment:

Additional context

I've noticed there's a similar bug elsewhere here has this been patched? or something similar?

bojiang commented 3 years ago

@edwin-19 It's an unofficial API of keras. I just removed it from bentoml in latest commits. Could you please try again on the master branch?

edwin-19 commented 3 years ago

@bojiang i didnt clone the repo to install bentoml

i used the pip install BentoML (version 0.9.2)

Should i clone the repo and install from there

bojiang commented 3 years ago

Should I clone the repo and install from there?

Yeah.

You can also simply run

pip install git+https://github.com/bentoml/BentoML.git

to install from the master branch.

edwin-19 commented 3 years ago

Ok that seemed to work. Thanks!

But i was wondering are you guys planning to move this to the official release?

bojiang commented 3 years ago

You must have noticed that the new version has been released. :)