tobegit3hub
tensorflow_template_application
Python

TensorFlow template application for deep learning

Last updated Jul 8, 2026
1.9k
Stars
706
Forks
19
Issues
0
Stars/day
Attention Score
82
Language breakdown
Python 68.7%
Java 10.0%
Objective-C++ 8.2%
C++ 3.9%
Scala 3.5%
Go 3.2%
โ–ธ Files click to expand
README

Introduction

It is the generic golden program for deep learning with TensorFlow.

  • [x] Data Formats
- [x] CSV - [x] LIBSVM - [x] TFRecords
  • [x] Predict Server
- [x] TensorFlow serving - [x] Python HTTP server
  • [x] Predict Client
- [x] Python gPRC client - [x] Java gPRC client - [x] Scala gPRC client - [x] Golang gRPC client - [x] C++ gRPC client - [x] Spark client - [x] Android client - [x] iOS client
  • [x] Network Models
- [x] Logistic regression - [x] Deep neural network - [x] Convolution neural network - [x] Wide and deep model - [x] Regression model - [x] Customized models
  • [x] Other Features
- [x] Checkpoint - [x] TensorBoard - [x] Exporter - [x] Dropout - [x] Optimizers - [x] Learning rate decay - [x] Batch normalization - [x] Benchmark mode - [x] Distributed training

Usage

Generate TFRecords

If your data is in CSV format, generate TFRecords like this.

cd ./data/cancer/

./generatecsvtfrecords.py

If your data is in LIBSVM format, generate TFRecords like this.

cd ./data/a8a/

./generatelibsvmtfrecord.py

For large dataset, you can use Spark to do that. Please refer to data.

Run Training

You can train with the default configuration.

./dense_classifier.py

./sparse_classifier.py

Using different models or hyperparameters is easy with TensorFlow flags.

./denseclassifier.py --batchsize 1024 --epochnumber 1000 --steptovalidate 10 --optmizier adagrad --model dnn --modelnetwork "128 32 8"

If you use other dataset like iris, no need to modify the code. Just run with parameters to specify the TFRecords files.

./denseclassifier.py --trainfile ./data/iris/iristrain.csv.tfrecords --validatefile ./data/iris/iristest.csv.tfrecords --featuresize 4 --labelsize 3  --enablecolored_log

./denseclassifier.py --trainfile ./data/iris/iristrain.csv --validatefile ./data/iris/iristest.csv --featuresize 4 --labelsize 3 --inputfileformat csv --enablecolored_log

If you want to use CNN model, try this command.

./denseclassifier.py --trainfile ./data/lung/fa7a21165ae152b13def786e6afc3edf.dcm.csv.tfrecords --validatefile ./data/lung/fa7a21165ae152b13def786e6afc3edf.dcm.csv.tfrecords --featuresize 262144 --labelsize 2 --batchsize 2 --validatebatchsize 2 --epoch_number -1 --model cnn

For boston housing dataset.

./denseclassifier.py --trainfile ./data/bostonhousing/train.csv.tfrecords --validatefile ./data/bostonhousing/train.csv.tfrecords --featuresize 13 --labelsize 1 --scenario regression  --batchsize 1 --validatebatchsize 1

Export The Model

After training, it will export the model automatically. Or you can export manually.

./dense_classifier.py --mode savedmodel

Validate The Model

If we want to run inference to validate the model, you can run like this.

./dense_classifier.py --mode inference

Use TensorBoard

The program will generate TensorFlow event files automatically.

tensorboard --logdir ./tensorboard/

Then go to http://127.0.0.1:6006 in the browser.

Serving and Predicting

The exported model is compatible with TensorFlow Serving. You can follow the document and run the tensorflowmodel_server.

./tensorflowmodelserver --port=9000 --modelname=dense --modelbase_path=./model/

We have provided some gRPC clients for dense and sparse models, such as Python predict client and Java predict client.

./predictclient.py --host 127.0.0.1 --port 9000 --modelname dense --model_version 1

mvn compile exec:java -Dexec.mainClass="com.tobe.DensePredictClient" -Dexec.args="127.0.0.1 9000 dense 1"

Contribution

This project is widely used for different tasks with dense or sparse data.

If you want to make contributions, feel free to open an issue or pull-request.

ยฉ 2026 GitRepoTrend ยท tobegit3hub/tensorflow_template_application ยท Updated daily from GitHub