https://github.com/valohai/tensorflow-example
TensorFlow examples for Valohai platform
https://github.com/valohai/tensorflow-example
machine-learning tensorflow
Last synced: 8 months ago
JSON representation
TensorFlow examples for Valohai platform
- Host: GitHub
- URL: https://github.com/valohai/tensorflow-example
- Owner: valohai
- Created: 2017-03-17T16:50:01.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2024-08-19T07:24:05.000Z (almost 2 years ago)
- Last Synced: 2024-08-19T08:45:05.532Z (almost 2 years ago)
- Topics: machine-learning, tensorflow
- Language: Python
- Homepage: https://valohai.com/
- Size: 96.7 KB
- Stars: 19
- Watchers: 11
- Forks: 61
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Valohai TensorFlow Examples
This repository serves as an example for the [Valohai MLOps platform][vh]. It implements handwritten digit detection
using
TensorFlow, based on [TensorFlow's example][ex].
The project demonstrates a complete machine learning pipeline consisting of five distinct steps:
1. **Preprocess data**: Prepare the input data for training.
2. **Train model**: Train the TensorFlow model using the preprocessed data.
3. **Batch inference**: Perform inference on a batch of data using the trained model.
4. **Compare predictions**: Analyze and compare the predictions generated by the model.
5. **Online inference deployment**: Deploy the trained model for online inference.
Within the Valohai platform, you can explore and test four different pipelines:
1. **Basic training pipeline**: This pipeline covers the essential steps for training the model.
2. **Three parallel trainings pipeline**: This pipeline demonstrates parallel training of the model using three
different configurations.
3. **Three parallel trainings with deployment pipeline**, including a special human approval block: This pipeline
showcases parallel training with deployment, incorporating a unique human approval block for manual verification.
4. Additional: **'Broken' pipeline**: This pipeline highlights a distinctive feature of Valohai that allows successful
nodes to be reused.
If you are just starting out, it is recommended to follow [the learning path][lp] in the Valohai documentation. This
learning path recreates the Train model step of this example.
[ex]: https://www.tensorflow.org/tutorials/quickstart/beginner
[vh]: https://valohai.com/
[lp]: https://docs.valohai.com/tutorials/learning-paths/fundamentals/valohai-utils/
## Running on Valohai
Login to the [Valohai app][app] and create a new project.
### Configure the repository:
Configure this repository as the project's repository, by following these steps:
1. Go to your project's page.
2. Navigate to the Settings tab.
3. Under the Repository section, locate the URL field.
4. Enter the URL of this repository.
5. Click on the Save button to save the changes.
Now you are ready to run executions, tasks and pipelines.
### **Running Executions:**
1. Go to the Executions tab in your project.
2. Create a new execution by selecting the predefined steps: batch-inference, compare-predictions, preprocess-dataset,
train-model.
3. Customize the execution parameters if needed.
4. Start the execution to run the selected step.
### Running Pipelines:
1. Navigate to the Pipelines tab.
2. Create a new pipeline by selecting one of the four available options. _Note: To run the pipeline with deployment you
should first create deployment with name 'deployment-test'._
3. Configure the pipeline settings.
4. Start the pipeline.
[app]: https://app.valohai.com
## Running on Valohai with Terminal
### Configure the repository:
To run your code on Valohai using the terminal, follow these steps:
1. Install Valohai on your machine by running the following command:
```bash
pip install valohai-cli valohai-utils
```
2. Log in to Valohai from the terminal using the command:
```bash
vh login
```
3. Create a project for your Valohai workflow.
Start by creating a directory for your project:
```bash
mkdir valohai-tensorflow-example
cd valohai-tensorflow-example
```
Then, create the Valohai project:
```bash
vh project create
```
4. Clone the repository to your local machine:
```bash
git clone https://github.com/valohai/tensorflow-example.git .
```
Congratulations! You have successfully cloned the repository, and you can now modify the code and run it using Valohai.
### Running Executions:
To run individual steps, execute the following command:
```bash
vh execution run --adhoc
```
For example, to run the preprocess-dataset step, use the command:
```bash
vh execution run preprocess-dataset --adhoc
```
### Running Pipelines:
To run pipelines, use the following command:
```bash
vh pipeline run --adhoc
```
For example, to run the three-trainings-pipeline-w-deployment pipeline, use the command:
```bash
vh pipeline run three-trainings-pipeline-w-deployment --adhoc
```
These commands will execute your code and run it on Valohai's platform.
## Running Locally
You can run all the steps of the pipeline locally. This requires Python 3.9 and specific packages, which you can install with:
```bash
pip install -r requirements.txt
```
The steps require different inputs to run, so you need to run them in order.
Preprocess data has all the required inputs defined as defaults and can be run with:
```bash
python preprocess_dataset.py
```
Train model requires the preprocessed dataset, but that is also defined as a default, so you can run:
```bash
python train_model.py
```
Batch inference requires both a model and some new data. The new data has default values, but the model needs to be provided, for example from an earlier train model run:
```bash
python batch_inference.py --model .valohai/outputs/{local_run_id}/train-model/model-{suffix}.h5
```
Compare predictions requires two or more batch inference results and optionally the corresponding models. We can run it for example like this:
```bash
python compare_predictions.py --predictions .valohai/outputs/{local_run_id}/batch-inference/predictions-{suffix}.json .valohai/outputs/{local_run_id}/batch-inference/predictions-{suffix}.json
```