{"id":14958918,"url":"https://github.com/ashutoshdongare/tensorflow-wide-deep-local-prediction","last_synced_at":"2025-08-12T15:10:42.824Z","repository":{"id":201566004,"uuid":"123953078","full_name":"AshutoshDongare/Tensorflow-Wide-Deep-Local-Prediction","owner":"AshutoshDongare","description":"This project demonstrates how to run and save predictions locally using exported tensorflow estimator model","archived":false,"fork":false,"pushed_at":"2018-03-06T05:42:57.000Z","size":30,"stargazers_count":30,"open_issues_count":1,"forks_count":27,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-07T01:53:16.233Z","etag":null,"topics":["csv","deep","estimator","local-predictions","machine-learning","prediction","python","tensorboard","tensorflow","tensorflow-examples","tensorflow-experiments","tensorflow-export-graph","tensorflow-models","tensorflow-samples","tensorflow-serving","tensorflow-tutorials","wide-and-deep"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AshutoshDongare.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2018-03-05T17:18:24.000Z","updated_at":"2023-12-18T05:44:15.000Z","dependencies_parsed_at":null,"dependency_job_id":"98785c99-fbdf-4ffc-a9fb-2bc697507ce9","html_url":"https://github.com/AshutoshDongare/Tensorflow-Wide-Deep-Local-Prediction","commit_stats":null,"previous_names":["ashutoshdongare/tensorflow-wide-deep-local-prediction"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/AshutoshDongare/Tensorflow-Wide-Deep-Local-Prediction","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AshutoshDongare%2FTensorflow-Wide-Deep-Local-Prediction","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AshutoshDongare%2FTensorflow-Wide-Deep-Local-Prediction/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AshutoshDongare%2FTensorflow-Wide-Deep-Local-Prediction/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AshutoshDongare%2FTensorflow-Wide-Deep-Local-Prediction/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AshutoshDongare","download_url":"https://codeload.github.com/AshutoshDongare/Tensorflow-Wide-Deep-Local-Prediction/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AshutoshDongare%2FTensorflow-Wide-Deep-Local-Prediction/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270082518,"owners_count":24523747,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-12T02:00:09.011Z","response_time":80,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csv","deep","estimator","local-predictions","machine-learning","prediction","python","tensorboard","tensorflow","tensorflow-examples","tensorflow-experiments","tensorflow-export-graph","tensorflow-models","tensorflow-samples","tensorflow-serving","tensorflow-tutorials","wide-and-deep"],"created_at":"2024-09-24T13:18:31.847Z","updated_at":"2025-08-12T15:10:42.791Z","avatar_url":"https://github.com/AshutoshDongare.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Tensorflow Wide \u0026 Deep Local Prediction to CSV\n## Overview \n\n**If you do not want to deploy full Tensorflow serving for production but still want to be able to perform local predictions and save the results, this sample will help you achieve that.**\n\n This sample builds on top of Tensorflow sample for implementing Wide \u0026 Deep estimator Model. Training part of the code has been adopted from [Tensorflow samples on Github](https://github.com/tensorflow/tensorflow). This sample exports Tensorflow estimator trained model to a local directory, loads \u0026 runs the saved model and saves the results to a CSV file. \n\nCheck out more details on [Tensorflow Wide and Deep estimator model](https://www.tensorflow.org/tutorials/wide_and_deep)\n\n## Running the code\n### Setup\n\n**Setup the tensorflow wide \u0026 Deep as described in the orginal sample given below**\n \nThe [Census Income Data Set](https://archive.ics.uci.edu/ml/datasets/Census+Income) that this sample uses for training is hosted by the [UC Irvine Machine Learning Repository](https://archive.ics.uci.edu/ml/datasets/). We have provided a script that downloads and cleans the necessary files.\n\n```\npython data_download.py\n```\n\nThis will download the files to `/tmp/census_data`. To change the directory, set the `--data_dir` flag.\n\n### Training\nYou can run the code locally as follows:\n\n```\npython wide_deep.py\n```\n\nThe model is saved to `/tmp/census_model` by default, which can be changed using the `--model_dir` flag.\n\nTo run the *wide* or *deep*-only models, set the `--model_type` flag to `wide` or `deep`. Other flags are configurable as well; see `wide_deep.py` for details.\n\nThe final accuracy should be over 83% with any of the three model types.\n\n### TensorBoard\n\nRun TensorBoard to inspect the details about the graph and training progression.\n\n```\ntensorboard --logdir=/tmp/census_model\n```\n\n## Exporting Trained Model\n\nWe will add code to export trained model. Add below code snippet right after the training the model and run the training and export.\n\n```\n  '''Export Trained Model for Serving'''\n  wideColumns, DeepColumns = build_model_columns()\n  feature_columns = DeepColumns\n  feature_spec = tf.feature_column.make_parse_example_spec(feature_columns)\n  export_input_fn = tf.estimator.export.build_parsing_serving_input_receiver_fn(feature_spec)\n  servable_model_dir = \"/tmp/census_exported\"\n  servable_model_path = model.export_savedmodel(servable_model_dir, export_input_fn)\n  print(\"Done Exporting at Path - %s\", servable_model_path )\n```\nWe are simply reusing ```build_model_columns()``` function present in training code to create features and export the model\n\nOnce we run the training and export, we should get a confirmation that the model has been exported at a path which looks like ```/tmp/census_exported/1520271391```. The last level would be different for each export so please note it down. we will be using it in the prediction code as mentioned in below section.\n \n## Running Predictions and Saving the results\n\n```wide_deep_predict.py``` contains code for loading saved model to run on input data ```census_input.csv``` and save the results to output CSV file ```census_output.csv```\n\nConfigure exported model path in ```wide_deep_predict.py``` as ```exported_path = '/tmp/census_exported/1520271391'``` \n\nThis code loads the exported model, reads input CSV line by line, prepares model input for prediction, runs prediction and writes results in Output CSV file.\n\nOutput file contains all input parameters in addition of results of prediction named as ```Predicted_income_bracket``` and ```probability```. Note that the first result column has values 0 or 1. Label value given in the training (Positive Label) will be treated as 1, ```\u003e50K``` in this case. If required you can write actual label values to CSV by checking the results.\n \n\n  \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fashutoshdongare%2Ftensorflow-wide-deep-local-prediction","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fashutoshdongare%2Ftensorflow-wide-deep-local-prediction","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fashutoshdongare%2Ftensorflow-wide-deep-local-prediction/lists"}