<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.4.2</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.alatus</groupId>
    <artifactId>DJL</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>DJL</name>
    <description>DJL</description>
    <url/>
    <licenses>
        <license/>
    </licenses>
    <developers>
        <developer/>
    </developers>
    <scm>
        <connection/>
        <developerConnection/>
        <tag/>
        <url/>
    </scm>
    <properties>
        <java.version>17</java.version>
        <djl.version>0.26.0</djl.version>
    </properties>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>ai.djl</groupId>
                <artifactId>bom</artifactId>
                <version>${djl.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <dependencies>
<!--        web依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
<!--        lombok依赖-->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
<!--        djl框架api-->
        <dependency>
            <groupId>ai.djl</groupId>
            <artifactId>api</artifactId>
        </dependency>
<!--        djl基本数据集-->
        <dependency>
            <groupId>ai.djl</groupId>
            <artifactId>basicdataset</artifactId>
        </dependency>
<!--        djl模型,模型动物园-->
        <dependency>
            <groupId>ai.djl</groupId>
            <artifactId>model-zoo</artifactId>
        </dependency>
<!--        djl的opencv-->
        <dependency>
            <groupId>ai.djl.opencv</groupId>
            <artifactId>opencv</artifactId>
        </dependency>
        <dependency>
            <groupId>ai.djl.mxnet</groupId>
            <artifactId>mxnet-engine</artifactId>
        </dependency>
<!--        pytorch依赖-->
        <dependency>
            <groupId>ai.djl.pytorch</groupId>
            <artifactId>pytorch-engine</artifactId>
            <version>0.26.0</version>
        </dependency>
        <dependency>
            <groupId>ai.djl.pytorch</groupId>
            <artifactId>pytorch-jni</artifactId>
            <version>2.1.1-0.26.0</version>
        </dependency>
<!--        pytorch用GPU-->
        <dependency>
            <groupId>ai.djl.pytorch</groupId>
            <artifactId>pytorch-native-cu121</artifactId>
            <classifier>win-x86_64</classifier>
            <version>2.1.1</version>
        </dependency>
        <dependency>
            <groupId>ai.djl.mxnet</groupId>
            <artifactId>mxnet-native-auto</artifactId>
            <version>1.8.0</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.4.2</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.alatus</groupId>
    <artifactId>DJL</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>DJL</name>
    <description>DJL</description>
    <url/>
    <licenses>
        <license/>
    </licenses>
    <developers>
        <developer/>
    </developers>
    <scm>
        <connection/>
        <developerConnection/>
        <tag/>
        <url/>
    </scm>
    <properties>
        <java.version>17</java.version>
        <djl.version>0.26.0</djl.version>
    </properties>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>ai.djl</groupId>
                <artifactId>bom</artifactId>
                <version>${djl.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <dependencies>
<!--        web依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
<!--        lombok依赖-->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
<!--        djl框架api-->
        <dependency>
            <groupId>ai.djl</groupId>
            <artifactId>api</artifactId>
        </dependency>
<!--        djl基本数据集-->
        <dependency>
            <groupId>ai.djl</groupId>
            <artifactId>basicdataset</artifactId>
        </dependency>
<!--        djl模型,模型动物园-->
        <dependency>
            <groupId>ai.djl</groupId>
            <artifactId>model-zoo</artifactId>
        </dependency>
<!--        djl的opencv-->
        <dependency>
            <groupId>ai.djl.opencv</groupId>
            <artifactId>opencv</artifactId>
        </dependency>
        <dependency>
            <groupId>ai.djl.mxnet</groupId>
            <artifactId>mxnet-engine</artifactId>
        </dependency>
<!--        pytorch依赖-->
        <dependency>
            <groupId>ai.djl.pytorch</groupId>
            <artifactId>pytorch-engine</artifactId>
            <version>0.26.0</version>
        </dependency>
        <dependency>
            <groupId>ai.djl.pytorch</groupId>
            <artifactId>pytorch-jni</artifactId>
            <version>2.1.1-0.26.0</version>
        </dependency>
<!--        pytorch用GPU-->
        <dependency>
            <groupId>ai.djl.pytorch</groupId>
            <artifactId>pytorch-native-cu121</artifactId>
            <classifier>win-x86_64</classifier>
            <version>2.1.1</version>
        </dependency>
        <dependency>
            <groupId>ai.djl.mxnet</groupId>
            <artifactId>mxnet-native-auto</artifactId>
            <version>1.8.0</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
package com.alatus.djl.app;

import com.alatus.djl.service.InterferenceService;
import com.alatus.djl.service.TrainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
public class DeepLearning {
    @Autowired
    private TrainService trainService;
    @Autowired
    private InterferenceService interferenceService;
    //训练模型的接口
    @GetMapping("/train")
    public String train() {
        return "train";
    }
    //进行推理
    @PostMapping("/result")
    public String predict(@RequestPart("file") MultipartFile image) {
//        返回结果的分类
        return "predict";
    }
}

 

package com.alatus.djl.app;

import com.alatus.djl.service.InterferenceService;
import com.alatus.djl.service.TrainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
public class DeepLearning {
    @Autowired
    private TrainService trainService;
    @Autowired
    private InterferenceService interferenceService;
    //训练模型的接口
    @GetMapping("/train")
    public String train() {
        return "train";
    }
    //进行推理
    @PostMapping("/result")
    public String predict(@RequestPart("file") MultipartFile image) {
//        返回结果的分类
        return "predict";
    }
}
package com.alatus.djl.service.impl;

import com.alatus.djl.service.InterferenceService;
import org.springframework.stereotype.Service;

@Service
public class InterferenceServiceImpl implements InterferenceService {
}

 

package com.alatus.djl.service.impl;

import com.alatus.djl.service.InterferenceService;
import org.springframework.stereotype.Service;

@Service
public class InterferenceServiceImpl implements InterferenceService {
}
package com.alatus.djl.service.impl;

import ai.djl.basicdataset.cv.classification.ImageFolder;
import ai.djl.modality.cv.transform.Resize;
import ai.djl.modality.cv.transform.ToTensor;
import com.alatus.djl.service.TrainService;
import org.springframework.stereotype.Service;
import java.nio.file.Path;
import java.nio.file.Paths;

@Service
public class TrainServiceImpl implements TrainService {
    @Override
    public void train(String datasetPath, String modelName, String modelPath) {
        Path path = Paths.get(datasetPath);
        ImageFolder folder = ImageFolder.builder().setRepositoryPath(path)//指定数据集的位置
                .setSampling(128, true)
                .optMaxDepth(10)
                .addTransform(new Resize(100, 100))
                .addTransform(new ToTensor())//把图片转为向量
                .build();
    }
}

 

package com.alatus.djl.service.impl;

import ai.djl.basicdataset.cv.classification.ImageFolder;
import ai.djl.modality.cv.transform.Resize;
import ai.djl.modality.cv.transform.ToTensor;
import com.alatus.djl.service.TrainService;
import org.springframework.stereotype.Service;
import java.nio.file.Path;
import java.nio.file.Paths;

@Service
public class TrainServiceImpl implements TrainService {
    @Override
    public void train(String datasetPath, String modelName, String modelPath) {
        Path path = Paths.get(datasetPath);
        ImageFolder folder = ImageFolder.builder().setRepositoryPath(path)//指定数据集的位置
                .setSampling(128, true)
                .optMaxDepth(10)
                .addTransform(new Resize(100, 100))
                .addTransform(new ToTensor())//把图片转为向量
                .build();
    }
}
package com.alatus.djl.service;

public interface InterferenceService {
}

 

package com.alatus.djl.service;

public interface InterferenceService {
}
package com.alatus.djl.service;

/**
 * @author: Alatus
 * @create: 2025-02-12 17:48
 * @description: DJL训练模型
 **/
public interface TrainService {
    /**
     *
     * @数据集的位置 datasetPath
     * @模型名字 modelName
     * @模型存放路径 modelPath
     */
    void train(String datasetPath,String modelName,String modelPath);
}

 

package com.alatus.djl.service;

/**
 * @author: Alatus
 * @create: 2025-02-12 17:48
 * @description: DJL训练模型
 **/
public interface TrainService {
    /**
     *
     * @数据集的位置 datasetPath
     * @模型名字 modelName
     * @模型存放路径 modelPath
     */
    void train(String datasetPath,String modelName,String modelPath);
}
Logo

火山引擎开发者社区是火山引擎打造的AI技术生态平台,聚焦Agent与大模型开发,提供豆包系列模型(图像/视频/视觉)、智能分析与会话工具,并配套评测集、动手实验室及行业案例库。社区通过技术沙龙、挑战赛等活动促进开发者成长,新用户可领50万Tokens权益,助力构建智能应用。

更多推荐