Skip to content

Commit

Permalink
fix ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
awkrail committed Sep 12, 2024
1 parent ba1d356 commit bb31c5d
Show file tree
Hide file tree
Showing 37 changed files with 204 additions and 1,847 deletions.
3 changes: 1 addition & 2 deletions lighthouse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations
under the License.
"""
from lighthouse import *
"""
16 changes: 16 additions & 0 deletions lighthouse/feature_extractor/audio_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@

from typing import Optional, Tuple

"""
Copyright $today.year LY Corporation
LY Corporation licenses this file to you under the Apache License,
version 2.0 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at:
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations
under the License.
"""


class AudioEncoder(BaseEncoder):
SAMPLE_RATE: int = 32000
Expand Down
16 changes: 16 additions & 0 deletions lighthouse/feature_extractor/base_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@

from typing import Tuple

"""
Copyright $today.year LY Corporation
LY Corporation licenses this file to you under the Apache License,
version 2.0 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at:
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations
under the License.
"""

class BaseEncoder(metaclass=abc.ABCMeta):
@abc.abstractmethod
def encode(
Expand Down
16 changes: 16 additions & 0 deletions lighthouse/feature_extractor/text_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@

from typing import Tuple

"""
Copyright $today.year LY Corporation
LY Corporation licenses this file to you under the Apache License,
version 2.0 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at:
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations
under the License.
"""

class TextEncoder(BaseEncoder):
def __init__(
self,
Expand Down
16 changes: 16 additions & 0 deletions lighthouse/feature_extractor/vision_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,22 @@

from typing import Optional, Tuple, List, Dict, Any

"""
Copyright $today.year LY Corporation
LY Corporation licenses this file to you under the Apache License,
version 2.0 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at:
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations
under the License.
"""

class VisionEncoder(BaseEncoder):

SLOWFAST_FRAMERATE: float = 30. # 30 is for Slowfast framerate
Expand Down
15 changes: 15 additions & 0 deletions lighthouse/feature_extractor/vision_encoders/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""
Copyright $today.year LY Corporation
LY Corporation licenses this file to you under the Apache License,
version 2.0 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at:
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations
under the License.
"""
15 changes: 15 additions & 0 deletions lighthouse/feature_extractor/vision_encoders/clip_v.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@

from typing import List, Optional

"""
Copyright $today.year LY Corporation
LY Corporation licenses this file to you under the Apache License,
version 2.0 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at:
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations
under the License.
"""

class Normalize:
def __init__(self,
Expand Down
16 changes: 16 additions & 0 deletions lighthouse/feature_extractor/vision_encoders/resnet152.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@

from typing import List, Optional

"""
Copyright $today.year LY Corporation
LY Corporation licenses this file to you under the Apache License,
version 2.0 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at:
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations
under the License.
"""

class GlobalAvgPool(torch.nn.Module):
def __init__(self):
super(GlobalAvgPool, self).__init__()
Expand Down
21 changes: 19 additions & 2 deletions lighthouse/feature_extractor/vision_encoders/slowfast.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,21 @@
from typing import List, Optional
from lighthouse.feature_extractor.vision_encoders.slowfast_model.model_loader import slowfast_model_loader

SLOWFAST_FEATURE_DIM = 2304
"""
Copyright $today.year LY Corporation
LY Corporation licenses this file to you under the Apache License,
version 2.0 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at:
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations
under the License.
"""

class Normalize(object):
def __init__(
Expand Down Expand Up @@ -34,6 +48,9 @@ def __call__(self, tensor):


class SlowFast:

SLOWFAST_FEATURE_DIM = 2304

def __init__(
self,
device: str,
Expand Down Expand Up @@ -76,7 +93,7 @@ def __call__(
slowfast_frames: torch.Tensor,
bsz: int = 45):
n_chunk = len(slowfast_frames)
features = torch.HalfTensor(n_chunk, SLOWFAST_FEATURE_DIM,
features = torch.HalfTensor(n_chunk, self.SLOWFAST_FEATURE_DIM,
device=self._device).fill_(0)
n_batch = int(math.ceil(n_chunk / bsz))
for i in range(n_batch):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import torch

from lighthouse.feature_extractor.vision_encoders.slowfast_model.utils.checkpoint import load_checkpoint
from lighthouse.feature_extractor.vision_encoders.slowfast_model.models import model_builder

"""
Copyright $today.year LY Corporation
Expand All @@ -15,10 +20,6 @@
"""
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
"""Build a video classification model."""
import torch

from lighthouse.feature_extractor.vision_encoders.slowfast_model.utils.checkpoint import load_checkpoint
from lighthouse.feature_extractor.vision_encoders.slowfast_model.models import model_builder

def slowfast_model_loader(
model_weight_path: str,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import torch
import torch.nn as nn

"""
Copyright $today.year LY Corporation
Expand All @@ -17,9 +20,6 @@

"""ResNe(X)t Head helper."""

import torch
import torch.nn as nn


class ResNetBasicHead(nn.Module):
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from lighthouse.feature_extractor.vision_encoders.slowfast_model.models.video_model_builder import SlowFastModel

"""
Copyright $today.year LY Corporation
Expand All @@ -15,8 +17,6 @@
"""
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
"""Model construction functions."""
import torch
from lighthouse.slowfast.slowfast.models.video_model_builder import SlowFastModel

def build_model():
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import torch
import torch.nn as nn

"""
Copyright $today.year LY Corporation
Expand All @@ -17,9 +20,6 @@

"""Non-local helper"""

import torch
import torch.nn as nn


class Nonlocal(nn.Module):
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import torch.nn as nn
from lighthouse.feature_extractor.vision_encoders.slowfast_model.models.nonlocal_helper import Nonlocal

"""
Copyright $today.year LY Corporation
Expand All @@ -17,9 +20,6 @@

"""Video models."""

import torch.nn as nn
from lighthouse.slowfast.slowfast.models.nonlocal_helper import Nonlocal


def get_trans_func(name):
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import torch.nn as nn

"""
Copyright $today.year LY Corporation
Expand All @@ -17,8 +19,6 @@

"""ResNe(X)t 3D stem helper."""

import torch.nn as nn


class VideoModelStem(nn.Module):
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import torch
import torch.nn as nn

import lighthouse.feature_extractor.vision_encoders.slowfast_model.utils.weight_init_helper as init_helper
from lighthouse.feature_extractor.vision_encoders.slowfast_model.models import head_helper, resnet_helper, stem_helper

"""
Copyright $today.year LY Corporation
Expand All @@ -17,12 +23,6 @@

"""Video models."""

import torch
import torch.nn as nn

import lighthouse.slowfast.slowfast.utils.weight_init_helper as init_helper
from lighthouse.slowfast.slowfast.models import head_helper, resnet_helper, stem_helper

# Number of blocks for different stages given the model depth.
_MODEL_STAGE_DEPTH = {50: (3, 4, 6, 3), 101: (3, 4, 23, 3)}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import re

"""
Copyright $today.year LY Corporation
Expand All @@ -18,8 +20,6 @@

"""Caffe2 to PyTorch checkpoint name converting utility."""

import re


def get_name_convert_func():
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
import os
import pickle
import torch

from collections import OrderedDict
from lighthouse.feature_extractor.vision_encoders.slowfast_model.utils.c2_model_loading import get_name_convert_func

"""
Copyright $today.year LY Corporation
Expand All @@ -13,18 +20,9 @@
License for the specific language governing permissions and limitations
under the License.
"""

# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.

"""Functions that handle saving and loading of checkpoints."""

import os
import pickle
from collections import OrderedDict
import torch

from lighthouse.slowfast.slowfast.utils.c2_model_loading import get_name_convert_func


def inflate_weight(state_dict_2d, state_dict_3d):
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import torch.nn as nn
from fvcore.nn.weight_init import c2_msra_fill

"""
Copyright $today.year LY Corporation
Expand All @@ -13,15 +16,9 @@
License for the specific language governing permissions and limitations
under the License.
"""

# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.

"""Utility function for weight initialization"""

import torch.nn as nn
from fvcore.nn.weight_init import c2_msra_fill


def init_weights(model, fc_init_std=0.01, zero_init_final_bn=True):
"""
Performs ResNet style weight initialization.
Expand Down
Loading

0 comments on commit bb31c5d

Please sign in to comment.