diff --git a/app/api/business/project_api.py b/app/api/business/project_api.py index 1238876..1e7c09d 100644 --- a/app/api/business/project_api.py +++ b/app/api/business/project_api.py @@ -159,4 +159,7 @@ def run_train(project_id: int, session: Session = Depends(get_db)): return rc.response_error("项目查询错误") if project_info.project_status == '1': return rc.response_error("项目当前存在训练进程,请稍后再试") - return StreamingResponse(ps.run_train_yolo(project_info, session), media_type="text/plain") + data, project, name, epochs, yolo_path, version_path = ps.run_train_yolo(project_info, session) + return StreamingResponse( + ps.run_commend(data, project, name, epochs, yolo_path, version_path, project_id, session), + media_type="text/plain") diff --git a/app/model/crud/project_info_crud.py b/app/model/crud/project_info_crud.py index 0f5e72e..2804ccd 100644 --- a/app/model/crud/project_info_crud.py +++ b/app/model/crud/project_info_crud.py @@ -51,14 +51,12 @@ def update_project_status(project_id: int, project_status: str, session: Session :return: """ if project_status == '2': - stmt = update(ProjectInfo).where(ProjectInfo.id == project_id).values({ - 'train_status': project_status, + session.query(ProjectInfo).filter_by(id=project_id).update({ + 'project_status': project_status, 'train_version': ProjectInfo.train_version + 1 }) - session.execute(stmt) else: - stmt = update(ProjectInfo).where(ProjectInfo.id == project_id).values({ - 'train_status': project_status + session.query(ProjectInfo).filter_by(id=project_id).update({ + 'project_status': project_status }) - session.execute(stmt) session.commit() diff --git a/app/service/project_service.py b/app/service/project_service.py index 41b1f4a..7434877 100644 --- a/app/service/project_service.py +++ b/app/service/project_service.py @@ -146,7 +146,8 @@ def run_train_yolo(project_info: ProjectInfoOut, session: Session): operate_img_label(project_images_val, img_path_val, label_path_val, session, label_id_list) # 打包完成开始训练,训练前,更改项目的训练状态 - pic.update_project_status(project_info.id, '1') + pic.update_project_status(project_info.id, '1', session) + # 开始训练 data = yaml_file project = os.file_path(runs_url, project_info.project_no, 'train') @@ -154,9 +155,20 @@ def run_train_yolo(project_info: ProjectInfoOut, session: Session): epochs = 10 yolo_path = os.file_path(yolo_url, 'train.py') + return data, project, name, epochs, yolo_path, version_path + + +def run_commend(data: str, project: str, + name: str, epochs: int, + yolo_path: str, version_path: str, + project_id: int, session: Session): # 启动子进程 with subprocess.Popen( - ["python", yolo_path, "--data=" + data, "--project=" + project, "--name=" + name, "--epochs=" + str(epochs)], + ["python", yolo_path, + "--data=" + data, + "--project=" + project, + "--name=" + name, + "--epochs=" + str(epochs)], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, @@ -173,12 +185,12 @@ def run_train_yolo(project_info: ProjectInfoOut, session: Session): # 等待进程结束并获取返回码 return_code = process.wait() if return_code != 0: - pic.update_project_status(project_info.id, '-1', session) + pic.update_project_status(project_id, '-1', session) else: - pic.update_project_status(project_info.id, '2', session) + pic.update_project_status(project_id, '2', session) # 然后保存版本训练信息 train = ProjectTrain() - train.project_id = project_info.id + train.project_id = project_id train.train_version = version_path bast_pt_path = os.file_path(project, name, 'weight', 'bast.pt') last_pt_path = os.file_path(project, name, 'weight', 'last.pt') diff --git a/test.py b/test.py new file mode 100644 index 0000000..35abe97 --- /dev/null +++ b/test.py @@ -0,0 +1,20 @@ +import subprocess + + +def main(): + data = 'D:\\syg\\yolov5\\datasets\\hqjvaj\\v1\\hqjvaj.yaml' + project = 'D:\\syg\\yolov5\\runs\\hqjvaj\\train' + name = 'v1' + epochs = 10 + yolo_path = 'yolov5/train.py' + + subprocess.run(["python", yolo_path, "--data=" + data, "--project=" + + project, "--name=" + name, "--epochs=" + str(epochs)], check=True) + + +if __name__ == "__main__": + """ + 如果此脚本被直接运行,则调用main()函数。 + 如果此脚本被其他脚本导入,则不会自动调用main()。 + """ + main() \ No newline at end of file diff --git a/yolov5/CITATION.cff b/yolov5/CITATION.cff new file mode 100644 index 0000000..c277230 --- /dev/null +++ b/yolov5/CITATION.cff @@ -0,0 +1,14 @@ +cff-version: 1.2.0 +preferred-citation: + type: software + message: If you use YOLOv5, please cite it as below. + authors: + - family-names: Jocher + given-names: Glenn + orcid: "https://orcid.org/0000-0001-5950-6979" + title: "YOLOv5 by Ultralytics" + version: 7.0 + doi: 10.5281/zenodo.3908559 + date-released: 2020-5-29 + license: AGPL-3.0 + url: "https://github.com/ultralytics/yolov5" diff --git a/yolov5/__init__.py b/yolov5/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/yolov5/pyproject.toml b/yolov5/pyproject.toml new file mode 100644 index 0000000..9680857 --- /dev/null +++ b/yolov5/pyproject.toml @@ -0,0 +1,147 @@ +# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license + +# Overview: +# This pyproject.toml file manages the build, packaging, and distribution of the Ultralytics library. +# It defines essential project metadata, dependencies, and settings used to develop and deploy the library. + +# Key Sections: +# - [build-system]: Specifies the build requirements and backend (e.g., setuptools, wheel). +# - [project]: Includes details like name, version, description, authors, dependencies and more. +# - [project.optional-dependencies]: Provides additional, optional packages for extended features. +# - [tool.*]: Configures settings for various tools (pytest, yapf, etc.) used in the project. + +# Installation: +# The Ultralytics library can be installed using the command: 'pip install ultralytics' +# For development purposes, you can install the package in editable mode with: 'pip install -e .' +# This approach allows for real-time code modifications without the need for re-installation. + +# Documentation: +# For comprehensive documentation and usage instructions, visit: https://docs.ultralytics.com + +[build-system] +requires = ["setuptools>=43.0.0", "wheel"] +build-backend = "setuptools.build_meta" + +# Project settings ----------------------------------------------------------------------------------------------------- +[project] +version = "7.0.0" +name = "YOLOv5" +description = "Ultralytics YOLOv5 for SOTA object detection, instance segmentation and image classification." +readme = "README.md" +requires-python = ">=3.8" +license = { "text" = "AGPL-3.0" } +keywords = ["machine-learning", "deep-learning", "computer-vision", "ML", "DL", "AI", "YOLO", "YOLOv3", "YOLOv5", "YOLOv8", "HUB", "Ultralytics"] +authors = [ + { name = "Glenn Jocher" }, + { name = "Ayush Chaurasia" }, + { name = "Jing Qiu" } +] +maintainers = [ + { name = "Glenn Jocher" }, + { name = "Ayush Chaurasia" }, + { name = "Jing Qiu" } +] +classifiers = [ + "Development Status :: 4 - Beta", + "Intended Audience :: Developers", + "Intended Audience :: Education", + "Intended Audience :: Science/Research", + "License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Topic :: Software Development", + "Topic :: Scientific/Engineering", + "Topic :: Scientific/Engineering :: Artificial Intelligence", + "Topic :: Scientific/Engineering :: Image Recognition", + "Operating System :: POSIX :: Linux", + "Operating System :: MacOS", + "Operating System :: Microsoft :: Windows", +] + +# Required dependencies ------------------------------------------------------------------------------------------------ +dependencies = [ + "matplotlib>=3.3.0", + "numpy>=1.22.2", + "opencv-python>=4.6.0", + "pillow>=7.1.2", + "pyyaml>=5.3.1", + "requests>=2.23.0", + "scipy>=1.4.1", + "torch>=1.8.0", + "torchvision>=0.9.0", + "tqdm>=4.64.0", # progress bars + "psutil", # system utilization + "py-cpuinfo", # display CPU info + "thop>=0.1.1", # FLOPs computation + "pandas>=1.1.4", + "seaborn>=0.11.0", # plotting + "ultralytics>=8.1.47" +] + +# Optional dependencies ------------------------------------------------------------------------------------------------ +[project.optional-dependencies] +dev = [ + "ipython", + "check-manifest", + "pre-commit", + "pytest", + "pytest-cov", + "coverage[toml]", + "mkdocs-material", + "mkdocstrings[python]", + "mkdocs-redirects", # for 301 redirects + "mkdocs-ultralytics-plugin>=0.0.34", # for meta descriptions and images, dates and authors +] +export = [ + "onnx>=1.12.0", # ONNX export + "coremltools>=7.0; platform_system != 'Windows'", # CoreML only supported on macOS and Linux + "openvino-dev>=2023.0", # OpenVINO export + "tensorflow>=2.0.0", # TF bug https://github.com/ultralytics/ultralytics/issues/5161 + "tensorflowjs>=3.9.0", # TF.js export, automatically installs tensorflow +] +# tensorflow>=2.4.1,<=2.13.1 # TF exports (-cpu, -aarch64, -macos) +# tflite-support # for TFLite model metadata +# scikit-learn==0.19.2 # CoreML quantization +# nvidia-pyindex # TensorRT export +# nvidia-tensorrt # TensorRT export +logging = [ + "comet", # https://docs.ultralytics.com/integrations/comet/ + "tensorboard>=2.13.0", + "dvclive>=2.12.0", +] +extra = [ + "ipython", # interactive notebook + "albumentations>=1.0.3", # training augmentations + "pycocotools>=2.0.6", # COCO mAP +] + +[project.urls] +"Bug Reports" = "https://github.com/ultralytics/yolov5/issues" +"Funding" = "https://ultralytics.com" +"Source" = "https://github.com/ultralytics/yolov5/" + +# Tools settings ------------------------------------------------------------------------------------------------------- +[tool.pytest] +norecursedirs = [".git", "dist", "build"] +addopts = "--doctest-modules --durations=30 --color=yes" + +[tool.isort] +line_length = 120 +multi_line_output = 0 + +[tool.ruff] +line-length = 120 + +[tool.docformatter] +wrap-summaries = 120 +wrap-descriptions = 120 +in-place = true +pre-summary-newline = true +close-quotes-on-newline = true + +[tool.codespell] +ignore-words-list = "crate,nd,strack,dota,ane,segway,fo,gool,winn,commend" +skip = '*.csv,*venv*,docs/??/,docs/mkdocs_??.yml' diff --git a/yolov5/requirements.txt b/yolov5/requirements.txt index ddaf993..dcd23bf 100644 --- a/yolov5/requirements.txt +++ b/yolov5/requirements.txt @@ -1,4 +1,4 @@ - YOLOv5 requirements +# YOLOv5 requirements # Usage: pip install -r requirements.txt # Base ------------------------------------------------------------------------ diff --git a/yolov5/utils/flask_rest_api/__init__.py b/yolov5/utils/flask_rest_api/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/yolov5/zshz.mp4 b/yolov5/zshz.mp4 new file mode 100644 index 0000000..c63237b Binary files /dev/null and b/yolov5/zshz.mp4 differ