Code Monkey home page Code Monkey logo

api_ner's Introduction

Simple Flask API for a Tensorflow Model

See the blog post covering the main steps.

To be hosted on Heroku (files Procfile, requirements.txt and runtime.txt).

To run locally,

python app.py

The model is from another repo on my github and is in the model directory. The flask app is defined in app.py which contains generic logic. The model-specific logic for the API is in the serve.py file.

An example of client is in the client directory.

api_ner's People

Contributors

gomesraf avatar guillaumegenthial avatar yuchenlin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

api_ner's Issues

No interface on the website (Windows)

Hello, I was trying to apply your code on my Windows machine. It seems that the code works perfectly fine, here are the last few lines when I run the app.py file (e.g. locally) in my Windows shell:


Restoring parameters from results/crf/model.weights/
 * Debugger is active!
 * Debugger PIN: 740-578-024
 * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)

Unfortunately, when I visit the IP address printed in the terminal, it says "unable to connect" (see the first attached image)

Changing to my local IP address, which is http://127.0.0.1:5000/, i can connect but the only thing I can see are the two words "Index API" in the top left corner (see the second attached image).

Do you think it is Windows related or am I doing something wrong?

image one:
cannot_connect

image two:
index

During handling of the above exception, another exception occurred -error

When I tried to execute python app.py, I get following error message.

Traceback (most recent call last):
File "/Users/admin/anaconda/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1022, in _do_call
return fn(*args)
File "/Users/admin/anaconda/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1004, in _run_fn
status, run_metadata)
File "/Users/admin/anaconda/lib/python3.6/contextlib.py", line 89, in exit
next(self.gen)
File "/Users/admin/anaconda/lib/python3.6/site-packages/tensorflow/python/framework/errors_impl.py", line 469, in raise_exception_on_not_ok_status
pywrap_tensorflow.TF_GetCode(status))
tensorflow.python.framework.errors_impl.NotFoundError: Key bi-lstm/bidirectional_rnn/bw/lstm_cell/biases not found in checkpoint
[[Node: save/RestoreV2 = RestoreV2[dtypes=[DT_FLOAT], _device="/job:localhost/replica:0/task:0/cpu:0"](_recv_save/Const_0, save/RestoreV2/tensor_names, save/RestoreV2/shape_and_slices)]]

During handling of the above exception, another exception occurred:

Saving model weights

When completing this project using TF2 many functions in base_model can't work due to TF2 not using Sessions. In serve.py the function restore_session() is called, what changes should be made to the code to do this in TF2.

I have tried
checkpoint_path = "training_3/cp.ckpt"#defining path where weights will be saved
checkpoint_dir = os.path.dirname(checkpoint_path)

cp_callback = tf.keras.callbacks.ModelCheckpoint(filepath=checkpoint_path,
save_weights_only=True,
verbose=1)#defining a function that is called in my model.fit by using: callbacks=[cp_callback])

I can then call load_weights but I am struggling with doing this within the get_model_api() in serve.py
Any help with this issue would be great, thanks.

Is there a concurrency issue?

Is there a concurrency issue with calling the model interface directly in the flask? For example, when multiple clients call the interface at the same time, the model performs multiple operations at the same time.

facing Attribute error, can you please help me in fixing this

PS C:\Users\RiyazHussain\Downloads\api_ner-master\api_ner-master> python app.py
2022-05-19 12:38:52.702197: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2022-05-19 12:38:52.702526: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
Traceback (most recent call last):
File "C:\Users\RiyazHussain\Downloads\api_ner-master\api_ner-master\app.py", line 23, in
model_api = get_model_api()
File "C:\Users\RiyazHussain\Downloads\api_ner-master\api_ner-master\serve.py", line 40, in get_model_api
model.build()
File "C:\Users\RiyazHussain\Downloads\api_ner-master\api_ner-master\model\ner_model.py", line 220, in build
self.add_placeholders()
File "C:\Users\RiyazHussain\Downloads\api_ner-master\api_ner-master\model\ner_model.py", line 24, in add_placeholders
self.word_ids = tf.placeholder(tf.int32, shape=[None, None],
AttributeError: module 'tensorflow' has no attribute 'placeholder'
PS C:\Users\RiyazHussain\Downloads\api_ner-master\api_ner-master>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.