Plant_AI 项目使用教程

Plant_AI 项目使用教程

Plant_AI Performing Leaf Image classification for Recognition of Plant Diseases using various types of CNN Architecture, For detection of Diseased Leaf and thus helping the increase in crop yield. Plant_AI 项目地址: https://gitcode.com/gh_mirrors/pl/Plant_AI

1. 项目目录结构及介绍

Plant_AI/
├── Assets/
├── Flask/
├── Models/
├── Src/
├── TestImages/
├── .gitignore
├── LICENSE
└── README.md
  • Assets: 存放项目相关的资源文件,如图片、文档等。
  • Flask: 包含Flask服务器的代码,用于部署和运行模型。
  • Models: 存放预训练的PyTorch模型文件。
  • Src: 包含构建模型的源代码。
  • TestImages: 存放用于模型测试的样本图像。
  • .gitignore: Git忽略文件,指定哪些文件或目录不需要被Git管理。
  • LICENSE: 项目的许可证文件,本项目使用MIT许可证。
  • README.md: 项目的说明文档,包含项目的基本介绍、使用方法等。

2. 项目的启动文件介绍

项目的启动文件位于 Flask/ 目录下,主要文件为 app.py。该文件是Flask应用的入口,负责启动Web服务器并加载模型进行预测。

# Flask/app.py
from flask import Flask, request, jsonify
from werkzeug.utils import secure_filename
import os
import torch
from Src.model import PlantDiseaseClassifier

app = Flask(__name__)

# 加载模型
model = PlantDiseaseClassifier()
model.load_state_dict(torch.load('Models/model.pth'))
model.eval()

@app.route('/predict', methods=['POST'])
def predict():
    if 'file' not in request.files:
        return jsonify({'error': 'No file part'})
    file = request.files['file']
    if file.filename == '':
        return jsonify({'error': 'No selected file'})
    if file:
        filename = secure_filename(file.filename)
        file.save(os.path.join('TestImages', filename))
        result = model.predict(os.path.join('TestImages', filename))
        return jsonify({'prediction': result})

if __name__ == '__main__':
    app.run(debug=True)

启动步骤

  1. 确保已安装Flask和PyTorch。
  2. 进入 Flask/ 目录。
  3. 运行 python app.py 启动Flask服务器。
  4. 访问 http://127.0.0.1:5000/predict 进行预测。

3. 项目的配置文件介绍

项目中没有显式的配置文件,但可以通过修改 Flask/app.py 中的代码来调整模型路径、上传文件路径等配置。

例如,修改模型路径:

model.load_state_dict(torch.load('Models/model.pth'))

可以根据需要修改 Models/model.pth 为其他模型文件路径。

其他配置

  • 上传文件路径: 默认上传文件路径为 TestImages/,可以通过修改 app.py 中的 file.save 路径来更改。
  • 端口号: 默认Flask服务器运行在5000端口,可以通过修改 app.run(debug=True, port=8080) 来更改端口号。

通过以上步骤,您可以顺利启动并配置Plant_AI项目,进行植物病害的图像分类和预测。

Plant_AI Performing Leaf Image classification for Recognition of Plant Diseases using various types of CNN Architecture, For detection of Diseased Leaf and thus helping the increase in crop yield. Plant_AI 项目地址: https://gitcode.com/gh_mirrors/pl/Plant_AI

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

郁俪晟Gertrude

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值