Closed mohan570 closed 1 year ago
Hello, which version of TensorFlow you are using? it should work with version 2.x
i changed like below now its working graph = tf.compat.v1.get_default_graph()
But , while bot running we are getting below error in endpoint api
File "\katana-assistant\mlmodels\katana-assistant-endpoint.py", line 153, in classify results = model.predict([input_data])[0] \ml_dl\env\lib\site-packages\tensorflow\python\keras\engine\training.py", line 127, in _method_wrapper if self._in_multi_worker_mode(): # pylint: disable=protected-access \ml_dl\env\lib\site-packages\tensorflow\python\keras\engine\training.py", line 2627, in _in_multi_worker_mode return self.distribute_strategy.extended._in_multi_worker_mode() # pylint: disable=protected-access \ml_dl\env\lib\site-packages\tensorflow\python\keras\engine\training.py", line 682, in distribute_strategy return self._distribution_strategy or ds_context.get_strategy() AttributeError: 'Sequential' object has no attribute '_distribution_strategy'
It seems like you are using TensorFlow v1. But the code was written for TensorFlow v2
Hi ,
am using below version only got via pip list
Python 3.8.6
tensorflow-2.3.1
Keras-2.4.3
Hi
Also, I have compiled the file katana-assistant-model.ipynb succeed and created the modelfile (katana-assistant-model.pkl)
In the katana-assistant-endpoint.py Endpoint i imported the pickle file (katana-assistant-model.pkl)
At last i run front jet its running on 8010 port local, but in the chat window if am request anything its replying below error i checked via pm2 logs id
*" 0|kat-bot | found in bag: hi 0|kat-bot | 0|kat-bot | [2020-10-21 00:58:06,113] ERROR in app: Exception on /katana-ml/api/v1.0/assistant [POST] 0|kat-bot | Traceback (most recent call last): 0|kat-bot | File "\env\lib\site-packages\flask\app.py", line 2447, in wsgi_app 0|kat-bot | response = self.full_dispatch_request() 0|kat-bot | File "\env\lib\site-packages\flask\app.py", line 1952, in full_dispatch_request 0|kat-bot | rv = self.handle_user_exception(e) 0|kat-bot | File "\env\lib\site-packages\flask_cors\extension.py", line 165, in wrapped_function 0|kat-bot | return cors_after_request(app.make_response(f(args, kwargs))) 0|kat-bot | File "\env\lib\site-packages\flask\app.py", line 1821, in handle_user_exception 0|kat-bot | reraise(exc_type, exc_value, tb) 0|kat-bot | File "\env\lib\site-packages\flask_compat.py", line 39, in reraise 0|kat-bot | raise value 0|kat-bot | File "\env\lib\site-packages\flask\app.py", line 1950, in full_dispatch_request 0|kat-bot | rv = self.dispatch_request() 0|kat-bot | File "\env\lib\site-packages\flask\app.py", line 1936, in dispatch_request 0|kat-bot | return self.view_functions[rule.endpoint](req.view_args) 0|kat-bot | File "\sample-bot\katana-assistant\mlmodels\katana-assistant-endpoint.py", line 153, in classify 0|kat-bot | results = model.predict([input_data])[0] 0|kat-bot | File "\env\lib\site-packages\tensorflow\python\keras\engine\training.py", line 127, in _method_wrapper 0|kat-bot | if self._in_multi_worker_mode(): # pylint: disable=protected-access 0|kat-bot | File "\env\lib\site-packages\tensorflow\python\keras\engine\training.py", line 2627, in _in_multi_worker_mode 0|kat-bot | return self.distribute_strategy.extended._in_multi_worker_mode() # pylint: disable=protected-access 0|kat-bot | File "\env\lib\site-packages\tensorflow\python\keras\engine\training.py", line 682, in distribute_strategy 0|kat-bot | return self._distribution_strategy or ds_context.get_strategy() 0|kat-bot | AttributeError: 'Sequential' object has no attribute '_distribution_strategy' "**
I will need to test it with your setup:
Python 3.8.6 tensorflow-2.3.1 Keras-2.4.3
I think originally this was tested with TensorFlow 2.0. You may try to downgrade the library and give it a try.
Hi find below my configuration
Also ,
Can you please let me know why the below error is apearing \env\lib\site-packages\tensorflow\python\keras\engine\training.py in distribute_strategy(self) return self._distribution_strategy or ds_context.get_strategy() AttributeError: 'Sequential' object has no attribute '_distribution_strategy'
I can't reproduce this error on my side. I google, there are similar issues reported, may be this will help: https://stackoverflow.com/questions/59765784/attributeerror-sequential-object-has-no-attribute-get-distribution-strategy
Hi Andrej Baranovskij,
when i run model creation script( katana-assistant-model.ipynb ). Its working fine and the pickle file was creating with the below code,
make_keras_picklable() pickle.dump(model, open("katana-assistant-model_1.pkl", "wb"))
-- I need your suggestion can i use the same assistant model script as API endpoint, Mode compilation, model training(Model.fit) in the katana-assistant-EndPoint itself without use pickle to load in the pre-trained model
Regards, Mohan A
I can't reproduce this error on my side. I google, there are similar issues reported, may be this will help: https://stackoverflow.com/questions/59765784/attributeerror-sequential-object-has-no-attribute-get-distribution-strategy
------ Actually i had used this before, for them the error coming on while they complile and train the model itself also they used tf logger and we dont anything here, also for us working fine when model compile, train and save as pickle file. Only the issue when we load the pickle file, graph = tf.getdefault graph() and model.predict these things.
Maybe this will help: Issue 4
Hi Team,
Am getting below error while connect flask api using pickle file. In pm2 logs finds below \sample-bot\katana-assistant\mlmodels\katana-assistant-endpoint.py", line 68, in
graph = tf.get_default_graph()
AttributeError: module 'tensorflow' has no attribute 'get_default_graph'