djl
v0.31.0
Deep Java图书馆(DJL)是一个开源的,高级的,发动机 - 不合时宜的Java框架,用于深度学习。 DJL设计为易于入门,易于使用Java开发人员。 DJL与任何其他常规Java库一样提供本地Java开发经验和功能。
您不必是机器学习/深度学习专家即可开始。您可以将现有的Java专业知识用作学习和使用机器学习和深度学习的坡道。您可以使用自己喜欢的IDE来构建,训练和部署模型。 DJL使将这些模型与您的Java应用程序集成在一起变得容易。
由于DJL是深度学习引擎不可知论,因此在创建项目时,您不必在引擎之间做出选择。您可以随时切换引擎。为了确保最佳性能,DJL还基于硬件配置提供了自动CPU/GPU选择。
DJL的人体工程学API界面旨在指导您采用最佳实践来完成深度学习任务。以下伪代码演示了运行推理:
// Assume user uses a pre-trained model from model zoo, they just need to load it
Criteria < Image , Classifications > criteria =
Criteria . builder ()
. optApplication ( Application . CV . OBJECT_DETECTION ) // find object detection model
. setTypes ( Image . class , Classifications . class ) // define input and output
. optFilter ( "backbone" , "resnet50" ) // choose network architecture
. build ();
Image img = ImageFactory . getInstance (). fromUrl ( "http://..." ); // read image
try ( ZooModel < Image , Classifications > model = criteria . loadModel ();
Predictor < Image , Classifications > predictor = model . newPredictor ()) {
Classifications result = predictor . predict ( img );
// get the classification and probability
...
}以下伪代码展示了运行训练:
// Construct your neural network with built-in blocks
Block block = new Mlp ( 28 * 28 , 10 , new int [] { 128 , 64 });
Model model = Model . newInstance ( "mlp" ); // Create an empty model
model . setBlock ( block ); // set neural network to model
// Get training and validation dataset (MNIST dataset)
Dataset trainingSet = new Mnist . Builder (). setUsage ( Usage . TRAIN ) ... . build ();
Dataset validateSet = new Mnist . Builder (). setUsage ( Usage . TEST ) ... . build ();
// Setup training configurations, such as Initializer, Optimizer, Loss ...
TrainingConfig config = setupTrainingConfig ();
Trainer trainer = model . newTrainer ( config );
/*
* Configure input shape based on dataset to initialize the trainer.
* 1st axis is batch axis, we can use 1 for initialization.
* MNIST is 28x28 grayscale image and pre processed into 28 * 28 NDArray.
*/
trainer . initialize ( new Shape ( 1 , 28 * 28 ));
EasyTrain . fit ( trainer , epoch , trainingSet , validateSet );
// Save the model
model . save ( modelDir , "mlp" );
// Close the resources
trainer . close ();
model . close ();计划于2025年1月发布DJL 0.32.0。
要从源构建,请先检查代码。一旦您在本地检查了代码,就可以使用Gradle如下构建它:
# for Linux/macOS:
./gradlew build
# for Windows:
gradlew build为了提高构建速度,您可以使用以下命令跳过单元测试:
# for Linux/macOS:
./gradlew build -x test
# for Windows:
gradlew build -x test将源项目导入Eclipse
# for Linux/macOS:
./gradlew eclipse
# for Windows:
gradlew eclipse
在日食
文件 - >导入 - > gradle->现有的gradle项目
注意:请将您的工作区文本编码设置设置为UTF-8
您可以阅读我们的社区论坛指南,遵循DJL,问题,讨论和RFC,以找出分享和查找DJL社区内容的最佳方法。
加入我们的Slack频道,与开发团队取得联系,以进行问题和讨论。
请按照我们的X(以前为Twitter)查看有关新内容,功能和发行版的最新信息。
关注我们关注我们获取djl 最新的内容!
该项目已根据APACHE-2.0许可获得许可。