Skip to content

Commit

Permalink
Merge pull request #2 from robin-maillot/267_integrate_yolo_in_mast_a…
Browse files Browse the repository at this point in the history
…lgorithm

267 integrate yolo in mast algorithm
  • Loading branch information
vnoblet-nanovare authored Nov 6, 2020
2 parents 49d4bc5 + 779d6a2 commit f6eca9a
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
*.data
*.json

#package
yolov5/*

*.cfg
!cfg/yolov3*.cfg

Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ Python 3.8 or later with all [requirements.txt](https://github.com/ultralytics/y
$ pip install -r requirements.txt
```

### Install as Module
To install yolov5 as a module you can either:
- Gret from git directly:
- `pip install git+https://github.com/robin-maillot/yolov5.git -f https://download.pytorch.org/whl/torch_stable.html`
- Clone the repo and:
- `python setup.py install` from the root folder
- `pip install . -f https://download.pytorch.org/whl/torch_stable.html` from the root folder
- `pip install .` from the root folder (on windows only compatible with pip<1.9)


## Tutorials

Expand Down
8 changes: 4 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# pip install -r requirements.txt
--find-links https://download.pytorch.org/whl/torch_stable.html


# base ----------------------------------------
Cython
matplotlib>=3.2.2
numpy>=1.18.5
opencv-python==3.4.11.43 # Due to core should be 3.4.11.43 but yolov5 recommends >=4.1.2 (Actually compatible with 3.4.11.43)
opencv-python>=3.4.11,<4.0.0 # Due to core should be 3.4.11.43 but yolov5 recommends >=4.1.2 (Actually compatible with 3.4.11.43)
pillow
PyYAML>=5.3
scipy>=1.4.1
tensorboard>=2.2
torch==1.6.0 # Not yet compatible with 1.7
torchvision==0.7.0 # Not yet compatible with 0.8
torch>=1.6,<1.7.0 # Not yet compatible with 1.7
torchvision>=0.7,<0.8.0 # Not yet compatible with 0.8
tqdm>=4.41.0

# coco ----------------------------------------
Expand Down
95 changes: 95 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import pathlib

import setuptools
from pkg_resources import parse_requirements

import shutil

MODULE_NAME = "nanovare_yolov5"


def copy_to_module():
current_path = pathlib.Path(".").resolve()
module_root_path = current_path / MODULE_NAME
module_root_path = module_root_path.relative_to(current_path)

if module_root_path.is_dir():
shutil.rmtree(module_root_path)

modules_moved = []
python_files = list(current_path.glob("**/*.py"))
for python_file_path in python_files:
python_file_path = python_file_path.relative_to(current_path)
if str(python_file_path) == "setup.py" or python_file_path.stem == "__init__":
continue
new_path = module_root_path / python_file_path
modules_moved.append(".".join((list(map(str,python_file_path.parents))[::-1][1:] + [python_file_path.stem])))
if not new_path.parent.is_dir():
new_path.parent.mkdir(parents=True, exist_ok=True)
# make an init
init_file = new_path.parent / "__init__.py"
init_file.touch()

shutil.copyfile(python_file_path, new_path)


# Rename modules
strings_to_replace = {}
for module_name in modules_moved:
strings_to_replace[f"from {module_name} "] = f"from {MODULE_NAME}.{module_name} "
strings_to_replace[f"import {module_name}"] = f"import {MODULE_NAME}.{module_name} "
strings_to_search_for = tuple(strings_to_replace)
new_python_files = list(module_root_path.glob("**/*.py"))
lines_changed = []

for python_file_path in new_python_files:
data = []
with python_file_path.open("r") as f:
for line in f:
if line.startswith(strings_to_search_for):
lines_changed.append(line)
for key in strings_to_search_for:
if line.startswith(key):
line = line.replace(key, strings_to_replace[key], 1)
data.append(line)
with python_file_path.open("w") as f:
for line in data:
f.write(line)

print(f"Changed {len(lines_changed)} lines to accommodate for imports.")


with open("README.md", "r") as fh:
long_description = fh.read()

with pathlib.Path('requirements.txt').open() as requirements_txt:
install_requires = [
str(requirement)
for requirement
in parse_requirements(requirements_txt)
]

copy_to_module()
modules = setuptools.find_packages(include=[MODULE_NAME, f"{MODULE_NAME}.*"])

setuptools.setup(
name=MODULE_NAME,
version="0.0.1",
author="nanovare",
author_email="vincent@nanovare.com, robin@nanovare.com",
description="yolov5 modifications for nanovare",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/robin-maillot/yolov5",
packages=modules,
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
python_requires='>=3.7',
dependency_links=[
"https://download.pytorch.org/whl/torch_stable.html",
],
install_requires=install_requires
)

0 comments on commit f6eca9a

Please sign in to comment.