BlairCurrey / swe-salary-predictor

1 stars 0 forks source link

adapt model for web #5

Closed BlairCurrey closed 2 years ago

BlairCurrey commented 2 years ago

The model needs to be utilized by the web app. The web app could either be a static site or a full-stack application.

If static, export the model in such a way (to json?) that it can be loaded using tensorflow js.

If doing a full stack application, then I could do it natively in python in the backend. Probably would still want to save it somehow first.

BlairCurrey commented 2 years ago

Direction is more clear at this point. the fast api server will listen for changes to the model table/document/whatever (db to be determined). These will be added periodically by a model builder service.

The model can be saved as a pickle, which can be unpickled by our server (when it sees there was an update).

BlairCurrey commented 2 years ago

Pickle is probably not the way to go. I did tf.keras.models.load_model('./dnn_model_keras') in analytics which saves files to a dnn_model_keras directory. Then I copied this directory to server and loaded it like model = keras.models.load_model('./dnn_model_keras'). Finally I predicted from user input with prediction = model.predict([num1, num2]).

This all works - it gives the same prediction as what I saw in jupyter nb (before and after saving model). It does have a warning in the console:

WARNING:tensorflow:Model was constructed with shape (None, None) for input KerasTensor(type_spec=TensorSpec(shape=(None, None), dtype=tf.float32, name='normalization_input'), name='normalization_input', description="created by layer 'normalization_input'"), but it was called on an input with incompatible shape (None,).
BlairCurrey commented 2 years ago

The question at this point is where to store these files and how to access them. I was planning on getting the changed model and loading it in the api but this may be more involved than I thought (downloading, unzipping, loading).

Perhaps a separate service would be better. Look for new data, retrain, save model, convert to tensorflow.js, provide to client via cdn? And/or provide converted tensorflow.js model via public js asset on server? Not sure if the tensorflow.js version would necessarily be compatible with my model though.

BlairCurrey commented 2 years ago

https://stackoverflow.com/questions/50174189/save-keras-model-to-database

This SO question gets at the same issue. Perhaps I can simply save the model files somewhere that the api can access. Then update the db with the path. API will either poll for updates to path or listen, if possible.