-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create NeptuneHook mechanism for automatic metadata logging #1
Merged
Merged
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
1c07e5b
add code for NeptuneHook
AleksanderWWW fb2581e
apply pre-commit suggestions
AleksanderWWW a028895
make logging final model conditional
AleksanderWWW 35336ab
add e2e test
AleksanderWWW 81bdc4d
add output dir to gitignore
AleksanderWWW 821b560
add torch to pyproject and pip installation of detectron to workflow
AleksanderWWW d604e9e
make custom_run_id a local variable
AleksanderWWW 2c75c71
remove windows from workflow
AleksanderWWW e7484b2
add run syncing before assertions
AleksanderWWW d9c2145
give time to upload files
AleksanderWWW b8ba20a
temporarily remove problematic assert to see how the rest goes
AleksanderWWW 65326e1
explicitly pass run to NeptuneHook and call sync after training
AleksanderWWW 567c8dc
sync active run, not the closed one
AleksanderWWW 78f86e0
sync before stoping run
AleksanderWWW c502ad5
change connecting with custom id to run id
AleksanderWWW e6f21c4
force installing lower version of numpy
AleksanderWWW 922ca97
add sync after uploading checkpoint
AleksanderWWW 0ade49b
increase number of epochs
AleksanderWWW dfaec88
fix checkpointing error
AleksanderWWW 38fc29c
add removing checkpoint files after train (+sync before)
AleksanderWWW a13e8ea
force lower version of fvcore
AleksanderWWW 1efc286
force precise version of fvcore
AleksanderWWW de82c8c
fix typo
AleksanderWWW 44304e4
bring back previous version specification of fvcore
AleksanderWWW 5465adf
modularize the code - create private methods for individual activities
AleksanderWWW c2fdbe8
verify type of config in _log_config method
AleksanderWWW c786969
verityf type of run before creating base handler
AleksanderWWW 0ff6907
fix checkpointing issue by uploading from stream
AleksanderWWW 56e1a7a
apply review suggestions
AleksanderWWW 27793e2
test accuracy, not loss
AleksanderWWW 24091e5
remove TODOs
AleksanderWWW a876116
delete train images
AleksanderWWW b101f49
add train images to gitignore
AleksanderWWW File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,3 +124,8 @@ venv.bak/ | |
.vscode | ||
|
||
stream.bin | ||
|
||
#detectron2 | ||
output/ | ||
|
||
datasets/coco/train2014/*jpg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
# Neptune - detectron2 integration | ||
|
||
TODO: Update docs link | ||
See [the official docs](https://docs.neptune.ai/integrations-and-supported-tools/model-training/). | ||
See [the official docs](https://docs.neptune.ai/integrations-and-supported-tools/model-training/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"info": | ||
{ | ||
"description": "COCO 2014 Dataset", | ||
"url": "http://cocodataset.org", | ||
"version": "1.0", | ||
"year": 2014, | ||
"contributor": "COCO Consortium", | ||
"date_created": "2017/09/01" | ||
}, | ||
"images": | ||
[{ | ||
"license": 5, "file_name": "COCO_train2014_000000057870.jpg", "coco_url": "http://images.cocodataset.org/train2014/COCO_train2014_000000057870.jpg", "height": 480, "width": 640, "date_captured": "2013-11-14 16:28:13", "flickr_url": "http://farm4.staticflickr.com/3153/2970773875_164f0c0b83_z.jpg", "id": 57870}, {"license": 5, "file_name": "COCO_train2014_000000384029.jpg", "coco_url": "http://images.cocodataset.org/train2014/COCO_train2014_000000384029.jpg", "height": 429, "width": 640, "date_captured": "2013-11-14 16:29:45", "flickr_url": "http://farm3.staticflickr.com/2422/3577229611_3a3235458a_z.jpg", "id": 384029}], | ||
"categories": [{"supercategory": "person","id": 1,"name": "person"},{"supercategory": "vehicle","id": 2,"name": "bicycle"},{"supercategory": "vehicle","id": 3,"name": "car"},{"supercategory": "vehicle","id": 4,"name": "motorcycle"},{"supercategory": "vehicle","id": 5,"name": "airplane"},{"supercategory": "vehicle","id": 6,"name": "bus"},{"supercategory": "vehicle","id": 7,"name": "train"},{"supercategory": "vehicle","id": 8,"name": "truck"},{"supercategory": "vehicle","id": 9,"name": "boat"},{"supercategory": "outdoor","id": 10,"name": "traffic light"},{"supercategory": "outdoor","id": 11,"name": "fire hydrant"},{"supercategory": "outdoor","id": 13,"name": "stop sign"},{"supercategory": "outdoor","id": 14,"name": "parking meter"},{"supercategory": "outdoor","id": 15,"name": "bench"},{"supercategory": "animal","id": 16,"name": "bird"},{"supercategory": "animal","id": 17,"name": "cat"},{"supercategory": "animal","id": 18,"name": "dog"},{"supercategory": "animal","id": 19,"name": "horse"},{"supercategory": "animal","id": 20,"name": "sheep"},{"supercategory": "animal","id": 21,"name": "cow"},{"supercategory": "animal","id": 22,"name": "elephant"},{"supercategory": "animal","id": 23,"name": "bear"},{"supercategory": "animal","id": 24,"name": "zebra"},{"supercategory": "animal","id": 25,"name": "giraffe"},{"supercategory": "accessory","id": 27,"name": "backpack"},{"supercategory": "accessory","id": 28,"name": "umbrella"},{"supercategory": "accessory","id": 31,"name": "handbag"},{"supercategory": "accessory","id": 32,"name": "tie"},{"supercategory": "accessory","id": 33,"name": "suitcase"},{"supercategory": "sports","id": 34,"name": "frisbee"},{"supercategory": "sports","id": 35,"name": "skis"},{"supercategory": "sports","id": 36,"name": "snowboard"},{"supercategory": "sports","id": 37,"name": "sports ball"},{"supercategory": "sports","id": 38,"name": "kite"},{"supercategory": "sports","id": 39,"name": "baseball bat"},{"supercategory": "sports","id": 40,"name": "baseball glove"},{"supercategory": "sports","id": 41,"name": "skateboard"},{"supercategory": "sports","id": 42,"name": "surfboard"},{"supercategory": "sports","id": 43,"name": "tennis racket"},{"supercategory": "kitchen","id": 44,"name": "bottle"},{"supercategory": "kitchen","id": 46,"name": "wine glass"},{"supercategory": "kitchen","id": 47,"name": "cup"},{"supercategory": "kitchen","id": 48,"name": "fork"},{"supercategory": "kitchen","id": 49,"name": "knife"},{"supercategory": "kitchen","id": 50,"name": "spoon"},{"supercategory": "kitchen","id": 51,"name": "bowl"},{"supercategory": "food","id": 52,"name": "banana"},{"supercategory": "food","id": 53,"name": "apple"},{"supercategory": "food","id": 54,"name": "sandwich"},{"supercategory": "food","id": 55,"name": "orange"},{"supercategory": "food","id": 56,"name": "broccoli"},{"supercategory": "food","id": 57,"name": "carrot"},{"supercategory": "food","id": 58,"name": "hot dog"},{"supercategory": "food","id": 59,"name": "pizza"},{"supercategory": "food","id": 60,"name": "donut"},{"supercategory": "food","id": 61,"name": "cake"},{"supercategory": "furniture","id": 62,"name": "chair"},{"supercategory": "furniture","id": 63,"name": "couch"},{"supercategory": "furniture","id": 64,"name": "potted plant"},{"supercategory": "furniture","id": 65,"name": "bed"},{"supercategory": "furniture","id": 67,"name": "dining table"},{"supercategory": "furniture","id": 70,"name": "toilet"},{"supercategory": "electronic","id": 72,"name": "tv"},{"supercategory": "electronic","id": 73,"name": "laptop"},{"supercategory": "electronic","id": 74,"name": "mouse"},{"supercategory": "electronic","id": 75,"name": "remote"},{"supercategory": "electronic","id": 76,"name": "keyboard"},{"supercategory": "electronic","id": 77,"name": "cell phone"},{"supercategory": "appliance","id": 78,"name": "microwave"},{"supercategory": "appliance","id": 79,"name": "oven"},{"supercategory": "appliance","id": 80,"name": "toaster"},{"supercategory": "appliance","id": 81,"name": "sink"},{"supercategory": "appliance","id": 82,"name": "refrigerator"},{"supercategory": "indoor","id": 84,"name": "book"},{"supercategory": "indoor","id": 85,"name": "clock"},{"supercategory": "indoor","id": 86,"name": "vase"},{"supercategory": "indoor","id": 87,"name": "scissors"},{"supercategory": "indoor","id": 88,"name": "teddy bear"},{"supercategory": "indoor","id": 89,"name": "hair drier"},{"supercategory": "indoor","id": 90,"name": "toothbrush"}], | ||
"annotations": [{"segmentation": [[91.48, 476.07, 90.67, 425.33, 130.76, 394.24, 126.67, 374.6, 116.85, 348.41, 119.31, 326.32, 136.49, 297.68, 161.86, 281.31, 189.68, 271.49, 217.5, 272.31, 247.78, 287.86, 262.51, 310.77, 259.24, 327.95, 255.96, 348.41, 243.69, 372.14, 228.96, 404.87, 223.23, 432.7, 236.32, 480.0, 217.5, 477.7, 204.41, 437.61, 193.77, 431.06, 191.32, 474.43, 182.32, 478.52, 163.49, 478.52, 173.31, 453.97, 174.13, 435.15, 161.86, 453.97, 155.31, 480.0, 136.49, 480.0, 129.94, 473.61, 127.49, 464.61, 121.76, 456.43, 116.03, 449.88, 108.67, 446.61, 107.03, 476.88, 97.21, 476.88]], "area": 23717.007900000004, "iscrowd": 0, "image_id": 57870, "bbox": [90.67, 271.49, 171.84, 208.51], "category_id": 62, "id": 2190436}, | ||
{"segmentation": [[62.5, 252.1, 48.73, 259.52, 33.9, 274.35, 33.9, 293.41, 30.72, 311.42, 36.01, 328.37, 51.9, 341.08, 60.38, 347.44, 80.5, 352.73, 100.63, 352.73, 106.99, 347.44, 145.12, 333.67, 157.83, 328.37, 175.84, 317.78, 188.55, 305.07, 194.9, 292.36, 197.02, 276.47, 191.73, 269.05, 183.25, 249.99, 183.25, 248.93, 172.66, 241.51, 163.13, 238.33, 149.36, 230.92, 143.0, 231.98, 131.35, 230.92, 118.64, 231.98, 99.57, 234.1, 94.27, 239.39, 75.21, 244.69, 68.85, 249.99]], "area": 14980.245250000007, "iscrowd": 0, "image_id": 384029, "bbox": [30.72, 230.92, 166.3, 121.81], "category_id": 61, "id": 2222000} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import pytest | ||
from detectron2 import model_zoo | ||
from detectron2.config import get_cfg | ||
from detectron2.engine import DefaultTrainer | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def cfg(): | ||
cfg = get_cfg() | ||
cfg.merge_from_file(model_zoo.get_config_file("COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml")) | ||
cfg.DATASETS.TRAIN = ("coco_2014_train",) | ||
cfg.DATASETS.TEST = () | ||
cfg.DATALOADER.NUM_WORKERS = 2 | ||
cfg.MODEL.WEIGHTS = model_zoo.get_checkpoint_url( | ||
"COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml" | ||
) # Let training initialize from model zoo | ||
cfg.SOLVER.IMS_PER_BATCH = 1 # This is the real "batch size" commonly known to deep learning people | ||
cfg.SOLVER.BASE_LR = 0.00025 | ||
cfg.SOLVER.MAX_ITER = 2 | ||
cfg.SOLVER.STEPS = [] # do not decay learning rate | ||
cfg.MODEL.ROI_HEADS.BATCH_SIZE_PER_IMAGE = 128 | ||
cfg.MODEL.ROI_HEADS.NUM_CLASSES = 80 | ||
cfg.MODEL.DEVICE = "cpu" | ||
yield cfg | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def trainer(cfg): | ||
yield DefaultTrainer(cfg) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import os | ||
|
||
import neptune.new as neptune | ||
|
||
from src.neptune_detectron2 import NeptuneHook | ||
from tests.utils import get_images | ||
|
||
|
||
def test_e2e(cfg, trainer): | ||
|
||
run = neptune.init_run() | ||
run_id = run["sys/id"].fetch() | ||
|
||
get_images() | ||
os.makedirs(cfg.OUTPUT_DIR, exist_ok=True) | ||
trainer.resume_or_load(resume=False) | ||
|
||
hook = NeptuneHook(run=run, log_checkpoints=True, log_model=True) | ||
trainer.register_hooks([hook]) | ||
trainer.train() | ||
|
||
npt_run = neptune.init_run(with_id=run_id) | ||
|
||
assert npt_run.exists("training/config") | ||
|
||
assert npt_run.exists("model/checkpoints/checkpoint_iter_0") | ||
|
||
assert npt_run.exists("model/checkpoints/checkpoint_final") | ||
|
||
assert isinstance(npt_run["training/model/summary"].fetch(), str) | ||
|
||
cls_accuracy_vals = npt_run["training/metrics/fast_rcnn/cls_accuracy"].fetch_values() | ||
assert 0 < cls_accuracy_vals.iloc[-1]["value"] <= 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import os | ||
import shutil | ||
|
||
|
||
def get_images(): | ||
img_dir = "./datasets/coco/train2014" | ||
if not os.path.isdir(img_dir) or len(os.listdir(img_dir)) == 0: | ||
os.makedirs(img_dir, exist_ok=True) | ||
os.system("wget http://images.cocodataset.org/train2014/COCO_train2014_000000057870.jpg") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need images stored in the repo if they are downloaded dynamically? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we don't need them, some gitignore entries might be a good idea. |
||
os.system("wget http://images.cocodataset.org/train2014/COCO_train2014_000000384029.jpg") | ||
shutil.move("COCO_train2014_000000057870.jpg", img_dir) | ||
shutil.move("COCO_train2014_000000384029.jpg", img_dir) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious, why not Windows?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://detectron2.readthedocs.io/en/latest/tutorials/install.html detetectron2 doesn't support Windows