-
Notifications
You must be signed in to change notification settings - Fork 677
Package code as a library #140
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
Open
kwikwag
wants to merge
3
commits into
princeton-vl:master
Choose a base branch
from
kwikwag:feature/package
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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,11 @@ | ||
| channels: | ||
| - pytorch | ||
| - defaults | ||
| dependencies: | ||
| - cudatoolkit=10.1 | ||
| - matplotlib | ||
| - opencv | ||
| - pytorch=1.6.0 | ||
| - scipy | ||
| - tensorboard | ||
| - torchvision=0.7.0 |
Empty file.
Empty file.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains hidden or 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 @@ | ||
| [build-system] | ||
| requires = [ | ||
| "setuptools>=42", | ||
| # TODO : coordinate versions with PYPI; until then use conda | ||
| # "matplotlib", | ||
| # "opencv-python", | ||
| # "torch==1.6.0", | ||
| # "scipy", | ||
| # "tensorboard", | ||
| # "torchvision==0.7.0", | ||
| ] | ||
| build-backend = "setuptools.build_meta" |
This file contains hidden or 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,24 @@ | ||
| [metadata] | ||
| name = raft | ||
| version = 0.0.1 | ||
| author = Zach Teed | ||
| author_email = zachteed@gmail.com | ||
| description = RAFT: Recurrent All Pairs Field Transforms for Optical Flow | ||
| long_description = file: README.md | ||
| long_description_content_type = text/markdown | ||
| url = https://github.com/princeton-vl/RAFT | ||
| project_urls = | ||
| Bug Tracker = https://github.com/princeton-vl/RAFT/issues | ||
| classifiers = | ||
| Programming Language :: Python :: 3 | ||
| License :: OSI Approved :: BSD License | ||
| Operating System :: OS Independent | ||
|
|
||
| [options] | ||
| package_dir = | ||
| = src | ||
| packages = find: | ||
| python_requires = >=3.6 | ||
|
|
||
| [options.packages.find] | ||
| where = src |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or 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 @@ | ||
| from . import core |
This file contains hidden or 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 @@ | ||
| from . import raft, update, extractor, datasets, corr, utils |
This file contains hidden or 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 hidden or 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
File renamed without changes.
This file contains hidden or 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
File renamed without changes.
This file contains hidden or 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 @@ | ||
| from . import augmentor, flow_viz, frame_utils, utils |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or 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,63 @@ | ||
| import argparse | ||
| import os | ||
| import cv2 | ||
| import glob | ||
| import numpy as np | ||
| import torch | ||
| from PIL import Image | ||
|
|
||
| from .core.utils import flow_viz | ||
| from . import inference | ||
|
|
||
|
|
||
|
|
||
| def viz(img, flo): | ||
| img = img[0].permute(1,2,0).cpu().numpy() | ||
| flo = flo[0].permute(1,2,0).cpu().numpy() | ||
|
|
||
| # map flow to rgb image | ||
| flo = flow_viz.flow_to_image(flo) | ||
| img_flo = np.concatenate([img, flo], axis=0) | ||
|
|
||
| # import matplotlib.pyplot as plt | ||
| # plt.imshow(img_flo / 255.0) | ||
| # plt.show() | ||
|
|
||
| cv2.imshow('image', img_flo[:, :, [2,1,0]]/255.0) | ||
| cv2.waitKey() | ||
|
|
||
|
|
||
| def demo(args): | ||
| device = torch.device('cuda') if torch.cuda.is_available() else torch.device('cpu') | ||
| model = inference.load_model( | ||
| args, | ||
| device, | ||
| args.model) | ||
|
|
||
| def log(x): | ||
| print(x) | ||
| return x | ||
|
|
||
| stream = ( | ||
| np.array(Image.open(log(impath))).astype(np.uint8) | ||
| for impath | ||
| in sorted( | ||
| glob.glob(os.path.join(args.path, '*.png')) + | ||
| glob.glob(os.path.join(args.path, '*.jpg')) | ||
| ) | ||
| ) | ||
|
|
||
| for image1, image2, flow_low, flow_up in inference.process_stream(stream, model, device, iters=20): | ||
| viz(image1, flow_up) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument('--model', required=True, help="restore checkpoint") | ||
| parser.add_argument('--path', required=True, help="dataset for evaluation") | ||
| parser.add_argument('--small', action='store_true', help='use small model') | ||
| parser.add_argument('--mixed_precision', action='store_true', help='use mixed precision') | ||
| parser.add_argument('--alternate_corr', action='store_true', help='use efficent correlation implementation') | ||
| args = parser.parse_args() | ||
|
|
||
| demo(args) |
This file contains hidden or 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 hidden or 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,63 @@ | ||
| import torch | ||
|
|
||
| from .core.utils.utils import InputPadder | ||
| from .core.raft import RAFT | ||
|
|
||
| def preprocess(image, device): | ||
| image = torch.from_numpy(image).permute(2, 0, 1).float() | ||
| image = image.unsqueeze(0) | ||
| image = image.to(device) | ||
| return image | ||
|
|
||
|
|
||
| def process_stream(stream, model, device, iters: int = 20): | ||
| """ | ||
| Processes an image stream and generates tuples of (image1, image2, flow_low, flow_up) | ||
| """ | ||
| it = iter(stream) | ||
| image1 = next(it) | ||
| image1 = preprocess(image1, device) | ||
|
|
||
| model.eval() | ||
| with torch.no_grad(): | ||
| for image2 in it: | ||
| # preprocessing | ||
| image2 = preprocess(image2, device) | ||
|
|
||
| # pad so shapes match | ||
| padder = InputPadder(image1.shape) | ||
| image1p, image2p = padder.pad(image1, image2) | ||
|
|
||
| # predict the flow | ||
| flow_low, flow_up = model(image1p, image2p, iters=iters, test_mode=True) | ||
| yield image1p, image2p, flow_low, flow_up | ||
|
|
||
| image1 = image2 | ||
|
|
||
|
|
||
| def cap_stream(cap, n: int = None): | ||
| """ | ||
| Create an iterable of images from an OpenCV video capture object. | ||
| :param n: Maximum number of frames to capture. None means unlimited. | ||
| """ | ||
| frame_idx = 0 | ||
| while True: | ||
| if n is not None and frame_idx >= n: | ||
| break | ||
| ret, frame = cap.read() | ||
| if not ret: | ||
| break | ||
| yield frame | ||
| frame_idx += 1 | ||
|
|
||
|
|
||
| def load_model( | ||
| raft_args, | ||
| device: torch.DeviceObjType, | ||
| checkpoint_path: str): | ||
| model = RAFT(raft_args) | ||
| if device.type == 'cuda': | ||
| model = torch.nn.DataParallel(model) | ||
| pretrained_weights = torch.load(checkpoint_path, map_location=device) | ||
| model.load_state_dict(pretrained_weights) | ||
| return model.to(device) |
This file contains hidden or 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
Oops, something went wrong.
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.
Whoops. I forgot to finish this bit, and modified
demo.pyinstead.