It is difficult to run tensorflow in a lambda:
- Size constraints from the lambda environment (<50MB)
- Native code compilation for the lambda environment
This family of packages will handle that heavy lifting for you.
See the GitHub repository for version information. This package will always contain a matrix of the currently supported AWS Lambda Node environments and the @tensorflow/tfjs-node
latest major versions.
Example matrix:
{
"lambda": ["nodejs10.x", "nodejs12.x"],
"tensorflow": ["1.7.4", "2.7.0"]
}
Example releases:
nodejs10.x-tf1.7.4.br
nodejs10.x-tf2.7.0.br
nodejs12.x-tf1.7.4.br
nodejs12.x-tf2.7.0.br
Using GitHub actions, these versions are updated daily around midnight. Lock your versions with the --save-exact
flag. Double check tfjs-node-lambda
and tfjs-node-lambda-releases
are the same matching versions.
npm install --save --save-exact tfjs-node-lambda tfjs-node-lambda-helpers
npm install --save-dev --save-exact tfjs-node-lambda-releases @tensorflow/tfjs-node @tensorflow/tfjs
import loadTf from 'tfjs-node-lambda';
Before running loadTf, you must ensure that the correct release is downloaded to the tmp dir. Use the tfjs-node-lambda-helpers
to do it for you.
TODO: recognize tfjs-node.br
as well as all release package names in the tmp dir.
const tf = await loadTf();
Due to having multiple supported versions of @tensorflow/tfjs-node
and an irregular bundle method, you must specify the types:
const tf: typeof import('@tensorflow/tfjs') = await loadTf();
See the npm package for more documentation.
We welcome contributions!
We use husky git hooks to automate commitizen. Due to this issue, we recommend running git commit -m "any or empty message"
and following the interactive mode. Thank you!