go-iris-tflite

command module
v0.0.0-...-7c07a46 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 14, 2026 License: MIT Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

go-iris-tflite

Classify iris flowers as setosa, versicolor or virginica from four measurements with a neural network, in Go only.

A sibling project of go-kani-tflite and go-fizzbuzz-tflite: the model is trained in pure Go with a hand-written backprop/Adam implementation — no Python and no TensorFlow — and the .tflite flatbuffer is generated directly from Go, then run with go-tflite using the XNNPACK delegate.

How it works

  1. cmd/train trains dense(4→8) tanh, dense(8→3) softmax — 67 parameters — on Fisher's 150 flowers (data/). Features are standardized for training and the standardization is folded back into the first layer's weights, so the saved model takes raw centimeters. Accuracy is reported with stratified 5-fold cross-validation (97.3%), then the final model is fit on all 150 flowers and written as iris_model.tflite.
  2. The command takes four measurements per flower — sepal length, sepal width, petal length, petal width, in cm — and runs them through the model with go-tflite.

Usage

Requires libtensorflowlite_c.so (see go-tflite for how to build it).

$ go run ./cmd/train      # optional: iris_model.tflite is checked in
$ go run . -all 5.1 3.5 1.4 0.2 6.4 3.2 4.5 1.5 7.7 3.8 6.7 2.2
(5.1, 3.5, 1.4, 0.2): setosa (99.8%)
  setosa      99.8%
  versicolor   0.2%
  virginica    0.0%
(6.4, 3.2, 4.5, 1.5): versicolor (99.2%)
  setosa       0.1%
  versicolor  99.2%
  virginica    0.8%
(7.7, 3.8, 6.7, 2.2): virginica (99.7%)
  setosa       0.0%
  versicolor   0.3%
  virginica   99.7%

Give any multiple of four numbers; each group of four is one flower. Omit -all to print only the winning species.

With no measurements it samples random flowers from data/iris.csv and checks each prediction against the class recorded in the CSV:

$ go run . -n 5
(5.2, 3.4, 1.4, 0.2): setosa (99.8%) ok
(6.1, 3, 4.6, 1.4): versicolor (98.9%) ok
(5.6, 2.8, 4.9, 2): virginica (98.5%) ok
(4.9, 2.4, 3.3, 1): versicolor (98.6%) ok
(6.9, 3.2, 5.7, 2.3): virginica (99.8%) ok
5/5 correct (100.0%)

-n picks the sample size (default 10; -n 150 scores the whole dataset) and -data points at a different CSV.

License

MIT

Author

Yasuhiro Matsumoto (a.k.a. mattn)

Documentation

Overview

Command go-iris-tflite classifies iris flowers as setosa, versicolor or virginica from four measurements (sepal length, sepal width, petal length, petal width, in cm) with the trained TensorFlow Lite model.

With no arguments it samples random flowers from the dataset, classifies them, and compares each prediction with the class recorded in the CSV.

Directories

Path Synopsis
cmd
train command
Command train trains the iris classifier on Fisher's 150 flowers with a hand-written backprop/Adam loop — no TensorFlow, no C — and writes the result as a TensorFlow Lite flatbuffer.
Command train trains the iris classifier on Fisher's 150 flowers with a hand-written backprop/Adam loop — no TensorFlow, no C — and writes the result as a TensorFlow Lite flatbuffer.
Package iris holds what the trainer and the classifier share: the four measurements, the three species, and the dataset loader.
Package iris holds what the trainer and the classifier share: the four measurements, the three species, and the dataset loader.
Package xnnpack enables the XNNPACK delegate through the symbols that libtensorflowlite_c.so itself exports, so no separate libXNNPACK / libtensorflowlite-delegate_xnnpack install is needed (which is what the go-tflite delegates/xnnpack package would link against).
Package xnnpack enables the XNNPACK delegate through the symbols that libtensorflowlite_c.so itself exports, so no separate libXNNPACK / libtensorflowlite-delegate_xnnpack install is needed (which is what the go-tflite delegates/xnnpack package would link against).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址