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

Simplify video_domain_adapter #292

Open
wants to merge 31 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
7ccd345
update .gitignore
xianyuanliu Jan 20, 2022
d955f73
update .gitignore
xianyuanliu Jan 20, 2022
1cecdf2
change root dir
xianyuanliu Jan 22, 2022
f9d0577
add EPIC100DatasetAccess
xianyuanliu Jan 22, 2022
046ef98
change transform_kind to transform
xianyuanliu Jan 22, 2022
77f1b0f
add NUM_SEGMENTS
xianyuanliu Jan 22, 2022
8a8581b
add INPUT_TYPE
xianyuanliu Jan 22, 2022
23b0e8e
add functions in VideoDatasetAccess for feature vector input
xianyuanliu Jan 22, 2022
f993f8d
add get_class_type
xianyuanliu Jan 22, 2022
60951d4
add CLASS_TYPE
xianyuanliu Jan 22, 2022
76f3e72
change num_classes to dict_num_classes
xianyuanliu Jan 22, 2022
feaf72a
update ClassNetVideo for dual-class task
xianyuanliu Jan 22, 2022
f5bc2b7
update test
xianyuanliu Jan 22, 2022
63c5be9
Merge branch 'main' into add_feature_vector_dataloader
xianyuanliu Jan 22, 2022
f89d8fc
change output folder to tb_logs
xianyuanliu Jan 22, 2022
b845a88
add get_class_type test
xianyuanliu Jan 22, 2022
ef74b72
update test_video_access
xianyuanliu Jan 22, 2022
b43802c
update config
xianyuanliu Jan 22, 2022
ba6f5c5
test bug fixes
xianyuanliu Jan 23, 2022
bdf9cbb
add VideoFeatureRecord in Videos.py & improve doc
xianyuanliu Jan 23, 2022
3ea4678
add epic100 test & bug fixes
xianyuanliu Jan 23, 2022
1540051
test bug fixes
xianyuanliu Jan 23, 2022
de0e6cd
test bug fixes
xianyuanliu Jan 23, 2022
cf1638b
add BaseAdaptTrainerVideo
xianyuanliu Jan 23, 2022
a2b3ce8
bug fixes
xianyuanliu Jan 23, 2022
4470413
add CLASS_TYPE
xianyuanliu Jan 23, 2022
37aeaac
add conditional function for class type
xianyuanliu Jan 23, 2022
a95a185
rename to num_classes
xianyuanliu Feb 7, 2022
ab23896
change root dir
xianyuanliu Feb 7, 2022
40861fc
Update doc
xianyuanliu Feb 7, 2022
dc4b990
Merge branch 'add_feature_vector_dataloader' into simplify_video_doma…
xianyuanliu Feb 7, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update ClassNetVideo for dual-class task
  • Loading branch information
xianyuanliu committed Jan 22, 2022
commit feaf72a94cfbcc47a22c0392dd410ce4061c2239
54 changes: 37 additions & 17 deletions kale/predict/class_domain_nets.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@

from kale.embed.video_i3d import Unit3D


# Previously FFSoftmaxClassifier
from kale.loaddata.video_access import get_class_type


class SoftmaxNet(nn.Module):
"""Regular and domain classifier network for regular-size images

Expand Down Expand Up @@ -126,30 +128,48 @@ def forward(self, input):
# For Video/Action Recognition, DataClassifier.
class ClassNetVideo(nn.Module):
"""Regular classifier network for video input.

Args:
dict_n_class (dict, optional): the dictionary of class number for specific dataset.
input_size (int, optional): the dimension of the final feature vector. Defaults to 512.
n_channel (int, optional): the number of channel for Linear and BN layers.
n_verb_channel (int, optional): the number of channel for Linear and BN layers for verb class.
n_noun_channel (int, optional): the number of channel for Linear and BN layers for noun class.
dropout_keep_prob (int, optional): the dropout probability for keeping the parameters.
n_class (int, optional): the number of classes. Defaults to 8.
class_type (string): the type of class. Option=["verb", "verb+noun"]
"""

def __init__(self, input_size=512, n_channel=100, dropout_keep_prob=0.5, n_class=8):
def __init__(
self,
dict_n_class,
input_size=512,
n_verb_channel=256,
n_noun_channel=512,
dropout_keep_prob=0.5,
class_type="verb",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to my comments above, we can implement the a class for the type of classes.

):
super(ClassNetVideo, self).__init__()
self._n_classes = n_class
self.fc1 = nn.Linear(input_size, n_channel)
self.bn1 = nn.BatchNorm1d(n_channel)
self.relu1 = nn.ReLU()
self.dp1 = nn.Dropout(dropout_keep_prob)
self.fc2 = nn.Linear(n_channel, n_class)

def n_classes(self):
return self._n_classes
self.verb, self.noun = get_class_type(class_type)
if self.verb:
self.n_verb_class = dict_n_class["verb"]
self.fc1 = nn.Linear(input_size, n_verb_channel)
self.bn1 = nn.BatchNorm1d(n_verb_channel)
self.relu1 = nn.ReLU()
self.dp1 = nn.Dropout(dropout_keep_prob)
self.fc11 = nn.Linear(n_verb_channel, self.n_verb_class)
if self.noun:
self.n_noun_class = dict_n_class["noun"]
self.fc2 = nn.Linear(input_size, n_noun_channel)
self.bn2 = nn.BatchNorm1d(n_noun_channel)
self.relu2 = nn.ReLU()
self.dp2 = nn.Dropout(dropout_keep_prob)
self.fc21 = nn.Linear(n_noun_channel, self.n_noun_class)

def forward(self, input):
x = self.dp1(self.relu1(self.bn1(self.fc1(input))))
x = self.fc2(x)
return x
x_verb = self.fc11(self.dp1(self.relu1(self.bn1(self.fc1(input)))))
if self.verb and not self.noun:
x_noun = None
if self.verb and self.noun:
x_noun = self.fc21(self.dp2(self.relu2(self.bn2(self.fc2(input)))))
return [x_verb, x_noun]


class ClassNetVideoConv(nn.Module):
Expand Down