-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
51 changed files
with
18,478 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
*.mp4 | ||
|
||
test_vid/ | ||
tttmp/ | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
pip-wheel-metadata/ | ||
share/python-wheels/ | ||
siamese-mask-rcnn/logs/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
*.py,cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
db.sqlite3-journal | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# pipenv | ||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. | ||
# However, in case of collaboration, if having platform-specific dependencies or dependencies | ||
# having no cross-platform support, pipenv may install dependencies that don't work, or not | ||
# install all needed dependencies. | ||
#Pipfile.lock | ||
|
||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow | ||
__pypackages__/ | ||
|
||
# Celery stuff | ||
celerybeat-schedule | ||
celerybeat.pid | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
# weight and test image | ||
*.h5 | ||
*.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import tensorflow as tf | ||
from . import slowfast_activity | ||
from tensorflow.keras.layers import Input | ||
from tensorflow.keras.utils import plot_model | ||
|
||
__all__=['network'] | ||
|
||
def resnet50(inputs, **kwargs): | ||
model = slowfast_activity.SlowFast_body(inputs, [3, 4, 6, 3], slowfast_activity.bottleneck, **kwargs) | ||
return model | ||
|
||
def resnet101(inputs, **kwargs): | ||
model = slowfast_activity.SlowFast_body(inputs, [3, 4, 23, 3], slowfast_activity.bottleneck, **kwargs) | ||
return model | ||
|
||
def resnet152(inputs, **kwargs): | ||
model = slowfast_activity.SlowFast_body(inputs, [3, 8, 36, 3], slowfast_activity.bottleneck, **kwargs) | ||
return model | ||
|
||
def resnet200(inputs, **kwargs): | ||
model = slowfast_activity.Slow_body(inputs, [3, 24, 36, 3], slowfast_activity.bottleneck, **kwargs) | ||
return model | ||
|
||
def resnet30(inputs, **kwargs): | ||
model = slowfast_activity.SlowFast_body(inputs, [3, 3, 6, 3], slowfast_activity.bottleneck, **kwargs) | ||
return model | ||
|
||
def get_model(out_dim): | ||
inputs = Input(shape=(24, 224, 224, 3)) | ||
model = resnet50(inputs, num_classes=out_dim) | ||
return model | ||
|
||
network = { | ||
'resnet50':resnet50, | ||
'resnet101':resnet101, | ||
'resnet152':resnet152, | ||
'resnet200':resnet200 | ||
} | ||
|
||
if __name__=="__main__": | ||
#tf.enable_eager_execution() | ||
x = tf.random_uniform([4, 64, 224, 224, 3]) | ||
inputs = Input(shape=(24, 224, 224, 3)) | ||
model = resnet50(inputs, num_classes=15) | ||
model.summary() | ||
plot_model(model, to_file='model.png') | ||
|
||
|
||
|
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,122 @@ | ||
import tensorflow as tf | ||
from tensorflow.keras import backend as K | ||
from tensorflow.keras.layers import Conv3D, BatchNormalization, ReLU, Add, MaxPool3D, GlobalAveragePooling3D, Concatenate, Dropout, Dense, Lambda | ||
from tensorflow.keras.models import Model | ||
from tensorflow.keras import Sequential | ||
|
||
|
||
|
||
def Conv_BN_ReLU(planes, kernel_size, strides=(1, 1, 1), padding='same', use_bias=False): | ||
return Sequential([ | ||
Conv3D(planes, kernel_size, strides=strides, padding=padding, use_bias=use_bias), | ||
BatchNormalization(), | ||
ReLU() | ||
]) | ||
|
||
|
||
def bottleneck(x, planes, stride=1, downsample=None, head_conv=1, use_bias=False): | ||
residual = x | ||
if head_conv == 1: | ||
x = Conv_BN_ReLU(planes, kernel_size=1, use_bias=use_bias)(x) | ||
elif head_conv == 3: | ||
x = Conv_BN_ReLU(planes, kernel_size=(3, 1, 1), use_bias=use_bias)(x) | ||
else: | ||
raise ValueError('Unsupported head_conv!!!') | ||
x = Conv_BN_ReLU(planes, kernel_size=(1, 3, 3), strides=(1, stride, stride), use_bias=use_bias)(x) | ||
x = Conv3D(planes*4, kernel_size=1, use_bias=use_bias)(x) | ||
x = BatchNormalization()(x) | ||
if downsample is not None: | ||
residual = downsample(residual) | ||
x = Add()([x, residual]) | ||
x = ReLU()(x) | ||
return x | ||
|
||
def datalayer(x, stride): | ||
return x[:, ::stride, :, :, :] | ||
|
||
def SlowFast_body(inputs, layers, block, num_classes, dropout=0.5): | ||
inputs_fast = Lambda(datalayer, name='data_fast', arguments={'stride':2})(inputs) | ||
inputs_slow = Lambda(datalayer, name='data_slow', arguments={'stride':16})(inputs) | ||
fast, lateral = Fast_body(inputs_fast, layers, block) | ||
slow = Slow_body(inputs_slow, lateral, layers, block) | ||
x = Concatenate()([slow, fast]) | ||
x = Dropout(dropout)(x) | ||
out = Dense(num_classes, activation='softmax')(x) | ||
return Model(inputs, out) | ||
|
||
|
||
|
||
def Fast_body(x, layers, block): | ||
fast_inplanes = 8 | ||
lateral = [] | ||
x = Conv_BN_ReLU(8, kernel_size=(5, 7, 7), strides=(1, 2, 2))(x) | ||
x = MaxPool3D(pool_size=(1, 3, 3), strides=(1, 2, 2), padding='same')(x) | ||
lateral_p1 = Conv3D(8*2, kernel_size=(5, 1, 1), strides=(8, 1, 1), padding='same', use_bias=False)(x) | ||
lateral.append(lateral_p1) | ||
x, fast_inplanes = make_layer_fast(x, block, 8, layers[0], head_conv=3, fast_inplanes=fast_inplanes) | ||
lateral_res2 = Conv3D(32*2, kernel_size=(5, 1, 1), strides=(8, 1, 1), padding='same', use_bias=False)(x) | ||
lateral.append(lateral_res2) | ||
x, fast_inplanes = make_layer_fast(x, block, 16, layers[1], stride=2, head_conv=3, fast_inplanes=fast_inplanes) | ||
lateral_res3 = Conv3D(64*2, kernel_size=(5, 1, 1), strides=(8, 1, 1), padding='same', use_bias=False)(x) | ||
lateral.append(lateral_res3) | ||
x, fast_inplanes = make_layer_fast(x, block, 32, layers[2], stride=2, head_conv=3, fast_inplanes=fast_inplanes) | ||
lateral_res4 = Conv3D(128*2, kernel_size=(5, 1, 1), strides=(8, 1, 1), padding='same', use_bias=False)(x) | ||
lateral.append(lateral_res4) | ||
x, fast_inplanes = make_layer_fast(x, block, 64, layers[3], stride=2, head_conv=3, fast_inplanes=fast_inplanes) | ||
x = GlobalAveragePooling3D()(x) | ||
return x, lateral | ||
|
||
def Slow_body(x, lateral, layers, block): | ||
slow_inplanes = 64 + 64//8*2 | ||
x = Conv_BN_ReLU(64, kernel_size=(1, 7, 7), strides=(1, 2, 2))(x) | ||
x = MaxPool3D(pool_size=(1, 3, 3), strides=(1, 2, 2), padding='same')(x) | ||
x = Concatenate()([x, lateral[0]]) | ||
x, slow_inplanes = make_layer_slow(x, block, 64, layers[0], head_conv=1, slow_inplanes=slow_inplanes) | ||
x = Concatenate()([x, lateral[1]]) | ||
x, slow_inplanes = make_layer_slow(x, block, 128, layers[1], stride=2, head_conv=1, slow_inplanes=slow_inplanes) | ||
x = Concatenate()([x, lateral[2]]) | ||
x, slow_inplanes = make_layer_slow(x, block, 256, layers[2], stride=2, head_conv=1, slow_inplanes=slow_inplanes) | ||
x = Concatenate()([x, lateral[3]]) | ||
x, slow_inplanes = make_layer_slow(x, block, 512, layers[3], stride=2, head_conv=1, slow_inplanes=slow_inplanes) | ||
x = GlobalAveragePooling3D()(x) | ||
return x | ||
|
||
|
||
def make_layer_fast(x, block, planes, blocks, stride=1, head_conv=1, fast_inplanes=8, block_expansion=4): | ||
downsample = None | ||
if stride != 1 or fast_inplanes != planes * block_expansion: | ||
downsample = Sequential([ | ||
Conv3D(planes*block_expansion, kernel_size=1, strides=(1, stride, stride), use_bias=False), | ||
BatchNormalization() | ||
]) | ||
fast_inplanes = planes * block_expansion | ||
x = block(x, planes, stride, downsample=downsample, head_conv=head_conv) | ||
for _ in range(1, blocks): | ||
x = block(x, planes, head_conv=head_conv) | ||
return x, fast_inplanes | ||
|
||
def make_layer_slow(x, block, planes, blocks, stride=1, head_conv=1, slow_inplanes=80, block_expansion=4): | ||
downsample = None | ||
if stride != 1 or slow_inplanes != planes * block_expansion: | ||
downsample = Sequential([ | ||
Conv3D(planes*block_expansion, kernel_size=1, strides = (1, stride, stride), use_bias=False), | ||
BatchNormalization() | ||
]) | ||
x = block(x, planes, stride, downsample, head_conv=head_conv) | ||
for _ in range(1, blocks): | ||
x = block(x, planes, head_conv=head_conv) | ||
slow_inplanes = planes * block_expansion + planes * block_expansion//8*2 | ||
return x, slow_inplanes | ||
|
||
|
||
|
||
|
||
|
||
|
||
if __name__=="__main__": | ||
tf.enable_eager_execution() | ||
conv = Conv_BN_ReLU(8, (5, 7, 7), strides=(1, 2, 2), padding='same') | ||
x = tf.random_uniform([1, 32, 224, 224, 3]) | ||
out = conv(x) | ||
out = MaxPool3D(pool_size=(1, 3, 3), strides=(1, 2, 2), padding='same')(out) | ||
print(out.get_shape()) |
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,32 @@ | ||
from tensorflow.keras.models import Sequential | ||
from tensorflow.keras.layers import Conv2D,MaxPooling2D,GlobalAveragePooling2D,Dense,Dropout | ||
from tensorflow import keras | ||
|
||
def get_model(): | ||
|
||
model = Sequential() | ||
model.add(Conv2D(filters=32,strides=(1,2), kernel_size=2, input_shape=(40,344,1), activation='relu',padding='same')) | ||
model.add(Dropout(0.2)) | ||
|
||
model.add(Conv2D(filters=64,strides=(1,2), kernel_size=2, activation='relu',padding='same')) | ||
model.add(Dropout(0.2)) | ||
|
||
model.add(Conv2D(filters=128,strides=(1,2), kernel_size=2, activation='relu',padding='same')) | ||
model.add(Dropout(0.2)) | ||
model.add(Conv2D(filters=128,strides=(2,2), kernel_size=2, activation='relu',padding='same')) | ||
model.add(Dropout(0.2)) | ||
|
||
model.add(Conv2D(filters=256,strides=(2,2), kernel_size=2, activation='relu',padding='same')) | ||
model.add(Dropout(0.2)) | ||
model.add(Conv2D(filters=512, kernel_size=2, activation='relu',padding='same')) | ||
model.add(Dropout(0.2)) | ||
|
||
model.add(GlobalAveragePooling2D()) | ||
|
||
model.add(Dense(1, activation='sigmoid')) | ||
return model | ||
|
||
|
||
if __name__ == '__main__': | ||
model = get_model() | ||
model.summary() |
Oops, something went wrong.