Skip to content

Labels: Load and use a custom TensorFlow model #127

Description

@Kazakuri

Issuehunt badges

It'd be nice to have some sort of documented procedure for loading a different TensorFlow model into PhotoPrism.

I don't have much experience with machine learning so I may be missing the mark with some of my assumptions but I tried to look into it a bit and wrote down my findings here.


From my initial investigation it looks like NASNet is downloaded when building the Docker image, and then the model is loaded from a static location in the application config.

By default that's ~/.local/share/photoprism/resources/nasnet so to replace the TensorFlow model you can just mount that folder with a new asset or otherwise change the assets-path in the config file.

From there I start to get a bit lost, when loading the model it seems like it loads a graph that's tagged with the name photoprism and labels from labels.txt in the same folder. It might be helpful to make the name of the tag that's loaded part of the configuration to make changing out models easier.

The documentation I found for LoadSavedModel doesn't tell me much, but my assumption is that it's only capable of loading protocol buffer models, so models must be trained and saved as .pb files or somehow converted to a .pb file.

The other thing I've noticed when looking through the code is that PhotoPrism uses models trained at 224x224, so I assume that if a custom model was trained at a different size then those numbers would need to be changed as well.


As a summary of what I've gathered it seems like these are the steps required:

  1. Get your model into the correct format (.pb).
    • I'm not sure how possible this is, but maybe provide resources on how to do this for other common model types? Ex. h5, cntk, pth/pkl
  2. Update the name of the graph being loaded from the model.
    • Either by updating the source code, or ideally a config file change.
  3. Update the resolution that the images are scaled to.
    • Either by updating the source code, or ideally a config file change.
  4. Mount your model folder as a volume to ~/.local/share/photoprism/resources/nasnet.
    • This should contain saved_model.pb and labels.txt.

IssueHunt Summary

Backers (Total: $60.00)

  • $60.00 have been anonymously funded.

Become a backer now!

Or submit a pull request to get the deposits!

Tips

Metadata

Metadata

Labels

aiArtificial Intelligence, Machine Learning (ML)help wantedHelp with this would be much appreciated!ideaFeedback wanted / feature requestreleasedAvailable in a stable release

Fields

No fields configured for Feature.

Projects

Status
Release 🌈

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions