This message was deleted.
# announcements
s
This message was deleted.
c
In BentoML, the BentoSerivce
@api
function is where we recommend putting the preprocessing code, here you can find some example projects: https://github.com/bentoml/gallery
You don’t need custom artifact for that
You can load a tf.SavedModel from disk directly as well, check out the docs here: https://docs.bentoml.org/en/latest/frameworks.html#tensorflow-2-0
l
My model subclasses tf.keras.Model and then overrides the train_step and test_step. I don't think savedmodel serializes these methods yet, so I have to build a new model and load the weights. Doesn't seem like the present artifact works like that, no?
c
I think this is supported out of the box, I might be wrong - cc @Jiang
j
@Luke Miner
tf.savedmodel
serializes methods that marked by
tf.function
. If your model is built with Keras API (including subclasses of
tf.keras.Model
) without a
tf.function
.
tf.savedmodel
would serializes the default method
__call__
with optional args
training
.
TensorFlowSavedModelArtifact
is using
tf.savedmodel
to serialize models.
l
mind blown
j
Yep. TensorFlow always gets things complex at beginning🤔. We just have some new examples using tf.keras API, it may help you: https://github.com/bentoml/gallery/blob/master/tensorflow/imdb/imdb_text_classification.ipynb
l
So would it be okay for me to create a class incorporating the artifacts in the
__init__
of
BentoService
?
Just tried it and it looks like I cannot. Is there any workaround? The reason that I ask is that I already have all my preprocessing packaged in a wrapper class around my tf.keras model. it would be nice to be able to reuse that code
c
Hey @Luke Miner - what’s the reason you want to do that?
You can just import that class in your bentoservice API function
what do you mean `create a class incorporating the artifacts in the 
__init__
 of 
BentoService
?`
l
i have a class with a model instance where the model instance is of type tf.keras.Model
the way my code is designed, this class manages preprocessing and post processing. so it would need to take artifacts.model in its constructor
does that make sense?
c
yes
just use this class in your BentoService class then
you just need to add custom logic in
__init__
right?
As long as you call
super
’s init method in your overrided init method, it should work
you can also just lazily initialize this class in your BentoService API callback function
l
those apply, but lazy initializing works fine for me. that's what I ended up trying
c
got it, thanks Luke, I will be working on a fix for those two tickets soon, but probably after the next release is out