Skip to content
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

Added requirements.txt file for version compatibility #35

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
*.swo
*.swm

*.pth

*.lprof

.cache
__pycache__
src/__pycache__


4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ from the paper [*Quo Vadis, Action Recognition? A New Model and the Kinetics Dat

The original (and official!) tensorflow code can be found [here](https://github.com/deepmind/kinetics-i3d/).

To install the required libraries: `pip install -r requirements.txt`

The heart of the transfer is the `i3d_tf_to_pt.py` script

Launch it with `python i3d_tf_to_pt.py --rgb` to generate the rgb checkpoint weight pretrained from ImageNet inflated initialization.
Expand All @@ -14,6 +16,8 @@ To generate the flow weights, use `python i3d_tf_to_pt.py --flow`.

You can also generate both in one run by using both flags simultaneously `python i3d_tf_to_pt.py --rgb --flow`.

If you have errors regarding Protobuf versions, try `PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python python i3d_tf_to_pt.py --rgb --flow`.

Note that the master version requires PyTorch 0.3 as it relies on the recent addition of ConstantPad3d that has been included in this latest release.

If you want to use pytorch 0.2 checkout the branch pytorch-02 which contains a simplified model with even padding on all sides (and the corresponding pytorch weight checkpoints).
Expand Down
9 changes: 6 additions & 3 deletions i3d_pt_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@


def run_demo(args):

device = torch.device('cuda') if torch.cuda.is_available() else torch.device('cpu')

kinetics_classes = [x.strip() for x in open(args.classes_path)]

def get_scores(sample, model):
sample_var = torch.autograd.Variable(torch.from_numpy(sample).cuda())
sample_var = torch.autograd.Variable(torch.from_numpy(sample).to(device))
out_var, out_logit = model(sample_var)
out_tensor = out_var.data.cpu()

Expand All @@ -30,7 +33,7 @@ def get_scores(sample, model):
i3d_rgb = I3D(num_classes=400, modality='rgb')
i3d_rgb.eval()
i3d_rgb.load_state_dict(torch.load(args.rgb_weights_path))
i3d_rgb.cuda()
i3d_rgb.to(device)

rgb_sample = np.load(args.rgb_sample_path).transpose(0, 4, 1, 2, 3)
out_rgb_logit = get_scores(rgb_sample, i3d_rgb)
Expand All @@ -40,7 +43,7 @@ def get_scores(sample, model):
i3d_flow = I3D(num_classes=400, modality='flow')
i3d_flow.eval()
i3d_flow.load_state_dict(torch.load(args.flow_weights_path))
i3d_flow.cuda()
i3d_flow.to(device)

flow_sample = np.load(args.flow_sample_path).transpose(0, 4, 1, 2, 3)
out_flow_logit = get_scores(flow_sample, i3d_flow)
Expand Down