internal/ai/tensorflow/README.md
Last Updated: March 3, 2026
internal/ai/tensorflow provides the shared TensorFlow helpers used by PhotoPrism’s built-in AI features (labels, NSFW, and FaceNet embeddings). It wraps SavedModel loading, input/output discovery, image tensor preparation, and label handling so higher-level packages can focus on domain logic.
SavedModel, GetModelTagsInfo, and GetInputAndOutputFromSavedModel discover and load SavedModel graphs with appropriate tags.Image, ImageTransform, and ImageTensorBuilder convert JPEG images to tensors with the configured resolution, color order, and resize strategy.AddSoftmax can insert a softmax op when a model exports logits.LoadLabels loads label lists for classification models.assets/models/ and are accessed via helpers in internal/ai/vision and internal/ai/classify.ModelInfo.Output.Logits is true, a softmax op is injected at load time.TensorFlow tensors are allocated in C memory and freed by Go GC finalizers in the TensorFlow bindings. Long-running inference can therefore show increasing RSS even when the Go heap is small. PhotoPrism periodically triggers garbage collection to return freed C-allocated tensor buffers to the OS. Control this behavior with:
PHOTOPRISM_TF_GC_EVERY (default 200, 0 disables).saved_model.pb plus variables/ exist under assets/models/<name>.Read less bytes than requested: The local assets/models/facenet/saved_model.pb file is usually incomplete or corrupted. Remove cached/downloaded files and reinstall:
rm -f /tmp/photoprism/facenet.ziprm -rf assets/models/facenetmake dep-tensorflow (or scripts/download-facenet.sh)go test ./internal/ai/face -run TestNet -count=1)vision.yml overrides (name, resolution, and TensorFlow.Input/Output).PHOTOPRISM_TF_GC_EVERY is set appropriately; model weights remain resident for the life of the process by design.internal/ai/vision/README.md — model registry, vision.yml configuration, and run schedulinginternal/ai/face/README.md — FaceNet embeddings and face-specific tuninginternal/ai/classify/README.md — classification workflow using TensorFlow helpersinternal/ai/nsfw/README.md — NSFW model usage and result mapping