Skip to content
This repository has been archived by the owner on Nov 21, 2023. It is now read-only.

Modularize the detectron library in a single python detectron module. #265

Closed
wants to merge 11 commits into from

Conversation

Erotemic
Copy link

@Erotemic Erotemic commented Mar 9, 2018

Currently, the setup.py in the detectron repo installs an assortment of modules with names like utils, ops, datasets, and core. These names are not descriptive on their own. Considering namespaces are one honking great idea, I've done some initial work to consolidate all of these modules as submodules of a module called detectron.

Therefore, when you would previously use import core, you now would write import detectron.core or from detectron import core.

This restructure introduces a lot of changes even though there is really no new logic. I realize that this makes reviewing and merging a PR like this difficult. To try and alleviate this process I scripted everything that I did to get to the state of this PR. This more effectively summarizes the real changes, and allows for what I did to be reproduced in case of any rebasing issues.

git mv lib/cmake cmake
git mv lib/CMakeLists.txt CMakeLists.txt
git mv lib/Makefile Makefile
git mv lib/setup.py setup.py
git mv lib detectron
touch detectron/__init__.py

git add detectron/__init__.py
git commit -am "Move files to modularize"

find . -iname '*.py' | xargs sed -i 's/^from \(datasets\|modeling\|core\|roi_data\|utils\) import/from detectron.\1 import/g'
git commit -am "import changes round1"

find . -iname '*.py' | xargs sed -i 's/^import \(datasets\|modeling\|core\|roi_data\|utils\)\(.*\) as /import detectron.\1\2 as /g'
git commit -am "import changes round2"

find . -iname '*.py' | xargs sed -i 's/^from \(datasets\|modeling\|core\|roi_data\|utils\)\./from detectron.\1./g'
git commit -am "import changes round3"

# Grep for unhandled cases
grep -I -ER '^import (datasets|modeling|core|roi_data|utils)'
grep -I -ER '^from (datasets|modeling|core|roi_data|utils)\.'

# And list them explicitly
find . -iname '*.py' | xargs sed -i 's/\butils.logging\b/detectron.utils.logging/g'
git commit -am "specific changes round1"

grep -I -ER '[^.]\butils.c2\b[^.]'
find . -iname '*.py' | xargs sed -i 's/\([^.]\)\butils.c2\b\([^.]\)/\1detectron.utils.c2\2/g'
find . -iname '*.py' | xargs sed -i 's/\([^.]\)\butils.c2$/\1detectron.utils.c2/g'
git commit -am "specific changes round2"


grep -I -ER '\bcore.config\b'
find . -iname '*.py' | xargs sed -i 's/\bcore\.config\b/detectron.core.config/g'
git commit -am "specific changes round3"

find . -iname '*.py' | xargs sed -i 's+lib/core/config+detectron/core/config+g'
git commit -am "specific changes round4"


grep -I -ER '\bmodeling\.name_compat\b'
find . -iname '*.py' | xargs sed -i 's/\bmodeling\.name_compat\b/detectron.modeling.name_compat/g'
find . -iname '*.py' | xargs sed -i 's/\broi_data\.minibatch\b/detectron.modeling.name_compat/g'
find . -iname '*.py' | xargs sed -i 's/\broi_data\.fast_rcnn\b/detectron.roi_data.fast_rcnn/g'
find . -iname '*.py' | xargs sed -i 's/\broi_data\.retinanet\b/detectron.roi_data.retinanet/g'
find . -iname '*.py' | xargs sed -i 's/\broi_data\.rpn\b/detectron.roi_data.rpn/g'
find . -iname '*.py' | xargs sed -i 's/\broi_data\.keypoint_rcnn\b/detectron.roi_data.keypoint_rcnn/g'
find . -iname '*.py' | xargs sed -i 's/\broi_data\.mask_rcnn\b/detectron.roi_data.mask_rcnn/g'
git commit -am "specific changes round5"


find . -iname '*.py' | xargs sed -i 's/^utils.c2/detectron.utils.c2/g'
git commit -am "specific changes round6"


sed -i 's|utils\.cython_|detectron.utils.cython_|g' setup.py
sed -i 's|utils/cython_|detectron/utils/cython_|g' setup.py
sed -i 's|utils/cython_|detectron/utils/cython_|g' setup.py

sed -i 's|/ops/|/detectron/ops/|g' CMakeLists.txt
sed -i 's|DESTINATION lib|DESTINATION detectron|g' CMakeLists.txt
git commit -am "setup and CMake fixups"

Note that I've been unable to get Detectron to actually build and work outside the docker container, so my testing of these changes has thusfar been minimal. Its quite possible that I forgot to search and replace a pattern or that one of my patterns was incorrect.

@rbgirshick
Copy link
Contributor

Addressed by 261f7db.

@rbgirshick rbgirshick closed this May 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants