Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ModelZoo
ResNet50_tensorflow
Commits
59d3d2a3
Commit
59d3d2a3
authored
Sep 03, 2020
by
Abdullah Rashwan
Committed by
A. Unique TensorFlower
Sep 03, 2020
Browse files
Internal change
PiperOrigin-RevId: 329988482
parent
c2d3fdc0
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
231 additions
and
11 deletions
+231
-11
official/vision/beta/__init__.py
official/vision/beta/__init__.py
+2
-2
official/vision/beta/configs/video_classification.py
official/vision/beta/configs/video_classification.py
+177
-0
official/vision/beta/configs/video_classification_test.py
official/vision/beta/configs/video_classification_test.py
+44
-0
official/vision/beta/dataloaders/classification_input_test.py
...cial/vision/beta/dataloaders/classification_input_test.py
+1
-1
official/vision/beta/ops/mask_ops.py
official/vision/beta/ops/mask_ops.py
+1
-1
official/vision/beta/tasks/__init__.py
official/vision/beta/tasks/__init__.py
+0
-1
official/vision/beta/tasks/maskrcnn.py
official/vision/beta/tasks/maskrcnn.py
+2
-2
official/vision/beta/tasks/maskrcnn_test.py
official/vision/beta/tasks/maskrcnn_test.py
+2
-2
official/vision/beta/tasks/retinanet.py
official/vision/beta/tasks/retinanet.py
+2
-2
No files found.
official/vision/beta/__init__.py
View file @
59d3d2a3
...
...
@@ -12,8 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""
NLP
package definition."""
"""
Vision
package definition."""
# Lint as: python3
# pylint: disable=unused-import
from
official.vision.beta
import
configs
from
official.vision.beta
import
tasks
from
official.vision.beta
.tasks.google
import
tasks
official/vision/beta/configs/video_classification.py
0 → 100644
View file @
59d3d2a3
# Lint as: python3
# Copyright 2020 The TensorFlow Authors. All Rights Reserved.
#
# Licensed 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
#
# http://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.
# ==============================================================================
"""Video classification configuration definition."""
from
typing
import
Optional
,
Tuple
import
dataclasses
from
official.core
import
exp_factory
from
official.modeling
import
hyperparams
from
official.modeling
import
optimization
from
official.modeling.hyperparams
import
config_definitions
as
cfg
from
official.vision.beta.configs
import
backbones_3d
from
official.vision.beta.configs
import
common
@
dataclasses
.
dataclass
class
DataConfig
(
cfg
.
DataConfig
):
"""The base configuration for building datasets."""
name
:
Optional
[
str
]
=
None
file_type
:
Optional
[
str
]
=
'tfrecord'
compressed_input
:
bool
=
False
split
:
str
=
'train'
feature_shape
:
Tuple
[
int
,
...]
=
(
64
,
224
,
224
,
3
)
temporal_stride
:
int
=
1
num_test_clips
:
int
=
1
num_classes
:
int
=
-
1
num_channels
:
int
=
3
num_examples
:
int
=
-
1
global_batch_size
:
int
=
128
num_devices
:
int
=
1
data_format
:
str
=
'channels_last'
dtype
:
str
=
'float32'
one_hot
:
bool
=
True
shuffle_buffer_size
:
int
=
64
cache
:
bool
=
False
input_path
:
str
=
''
is_training
:
bool
=
True
cycle_length
:
int
=
10
min_image_size
:
int
=
256
def
kinetics600
(
is_training
):
"""Generated Kinectics 600 dataset configs."""
return
DataConfig
(
name
=
'kinetics600'
,
num_classes
=
600
,
is_training
=
is_training
,
split
=
'train'
if
is_training
else
'valid'
,
num_examples
=
366016
if
is_training
else
27780
,
feature_shape
=
(
64
,
224
,
224
,
3
)
if
is_training
else
(
250
,
224
,
224
,
3
))
@
dataclasses
.
dataclass
class
VideoClassificationModel
(
hyperparams
.
Config
):
"""The model config."""
backbone
:
backbones_3d
.
Backbone3D
=
backbones_3d
.
Backbone3D
(
type
=
'resnet_3d'
,
resnet_3d
=
backbones_3d
.
ResNet3D50
())
norm_activation
:
common
.
NormActivation
=
common
.
NormActivation
()
dropout_rate
:
float
=
0.2
add_head_batch_norm
:
bool
=
False
@
dataclasses
.
dataclass
class
Losses
(
hyperparams
.
Config
):
one_hot
:
bool
=
True
label_smoothing
:
float
=
0.0
l2_weight_decay
:
float
=
0.0
@
dataclasses
.
dataclass
class
VideoClassificationTask
(
cfg
.
TaskConfig
):
"""The task config."""
model
:
VideoClassificationModel
=
VideoClassificationModel
()
train_data
:
DataConfig
=
DataConfig
(
is_training
=
True
)
validation_data
:
DataConfig
=
DataConfig
(
is_training
=
False
)
losses
:
Losses
=
Losses
()
gradient_clip_norm
:
float
=
-
1.0
def
add_trainer
(
experiment
:
cfg
.
ExperimentConfig
,
train_batch_size
:
int
,
eval_batch_size
:
int
,
learning_rate
:
float
=
1.6
,
train_epochs
:
int
=
44
,
warmup_epochs
:
int
=
5
):
"""Add and config a trainer to the experiment config."""
if
experiment
.
task
.
train_data
.
num_examples
<=
0
:
raise
ValueError
(
'Wrong train dataset size {!r}'
.
format
(
experiment
.
task
.
train_data
))
if
experiment
.
task
.
validation_data
.
num_examples
<=
0
:
raise
ValueError
(
'Wrong validation dataset size {!r}'
.
format
(
experiment
.
task
.
validation_data
))
experiment
.
task
.
train_data
.
global_batch_size
=
train_batch_size
experiment
.
task
.
validation_data
.
global_batch_size
=
eval_batch_size
steps_per_epoch
=
experiment
.
task
.
train_data
.
num_examples
//
train_batch_size
experiment
.
trainer
=
cfg
.
TrainerConfig
(
steps_per_loop
=
steps_per_epoch
,
summary_interval
=
steps_per_epoch
,
checkpoint_interval
=
steps_per_epoch
,
train_steps
=
train_epochs
*
steps_per_epoch
,
validation_steps
=
experiment
.
task
.
validation_data
.
num_examples
//
eval_batch_size
,
validation_interval
=
steps_per_epoch
,
optimizer_config
=
optimization
.
OptimizationConfig
({
'optimizer'
:
{
'type'
:
'sgd'
,
'sgd'
:
{
'momentum'
:
0.9
,
'nesterov'
:
True
,
}
},
'learning_rate'
:
{
'type'
:
'cosine'
,
'cosine'
:
{
'initial_learning_rate'
:
learning_rate
,
'decay_steps'
:
train_epochs
*
steps_per_epoch
,
}
},
'warmup'
:
{
'type'
:
'linear'
,
'linear'
:
{
'warmup_steps'
:
warmup_epochs
*
steps_per_epoch
,
'warmup_learning_rate'
:
0
}
}
}))
return
experiment
@
exp_factory
.
register_config_factory
(
'video_classification'
)
def
video_classification
()
->
cfg
.
ExperimentConfig
:
"""Video classification general."""
return
cfg
.
ExperimentConfig
(
task
=
VideoClassificationTask
(),
trainer
=
cfg
.
TrainerConfig
(),
restrictions
=
[
'task.train_data.is_training != None'
,
'task.validation_data.is_training != None'
,
'task.train_data.num_classes == task.validation_data.num_classes'
,
])
@
exp_factory
.
register_config_factory
(
'video_classification_kinetics600'
)
def
video_classification_kinetics600
()
->
cfg
.
ExperimentConfig
:
"""Video classification on Videonet with resnet."""
train_dataset
=
kinetics600
(
is_training
=
True
)
validation_dataset
=
kinetics600
(
is_training
=
False
)
task
=
VideoClassificationTask
(
model
=
VideoClassificationModel
(
backbone
=
backbones_3d
.
Backbone3D
(
type
=
'resnet_3d'
,
resnet_3d
=
backbones_3d
.
ResNet3D50
()),
norm_activation
=
common
.
NormActivation
(
norm_momentum
=
0.9
,
norm_epsilon
=
1e-5
)),
losses
=
Losses
(
l2_weight_decay
=
1e-4
),
train_data
=
train_dataset
,
validation_data
=
validation_dataset
)
config
=
cfg
.
ExperimentConfig
(
task
=
task
,
restrictions
=
[
'task.train_data.is_training != None'
,
'task.validation_data.is_training != None'
,
'task.train_data.num_classes == task.validation_data.num_classes'
,
])
add_trainer
(
config
,
train_batch_size
=
1024
,
eval_batch_size
=
64
)
return
config
official/vision/beta/configs/video_classification_test.py
0 → 100644
View file @
59d3d2a3
# Lint as: python3
# Copyright 2020 The TensorFlow Authors. All Rights Reserved.
#
# Licensed 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
#
# http://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.
# ==============================================================================
"""Tests for video_classification."""
# pylint: disable=unused-import
from
absl.testing
import
parameterized
import
tensorflow
as
tf
from
official.core
import
exp_factory
from
official.modeling.hyperparams
import
config_definitions
as
cfg
from
official.vision
import
beta
from
official.vision.beta.configs
import
video_classification
as
exp_cfg
class
VideoClassificationConfigTest
(
tf
.
test
.
TestCase
,
parameterized
.
TestCase
):
@
parameterized
.
parameters
((
'video_classification'
,),
(
'video_classification_kinetics600'
,))
def
test_video_classification_configs
(
self
,
config_name
):
config
=
exp_factory
.
get_exp_config
(
config_name
)
self
.
assertIsInstance
(
config
,
cfg
.
ExperimentConfig
)
self
.
assertIsInstance
(
config
.
task
,
exp_cfg
.
VideoClassificationTask
)
self
.
assertIsInstance
(
config
.
task
.
model
,
exp_cfg
.
VideoClassificationModel
)
self
.
assertIsInstance
(
config
.
task
.
train_data
,
exp_cfg
.
DataConfig
)
config
.
task
.
train_data
.
is_training
=
None
with
self
.
assertRaises
(
KeyError
):
config
.
validate
()
if
__name__
==
'__main__'
:
tf
.
test
.
main
()
official/vision/beta/dataloaders/classification_input_test.py
View file @
59d3d2a3
...
...
@@ -80,7 +80,7 @@ class ParserTest(parameterized.TestCase, tf.test.TestCase):
def
test_parser
(
self
,
output_size
,
dtype
,
is_training
):
params
=
cfg
.
DataConfig
(
input_path
=
'
/readahead/200M/placer/prod/home/distbelief/imagenet-tensorflow/
imagenet-2012-tfrecord/train*'
,
input_path
=
'imagenet-2012-tfrecord/train*'
,
global_batch_size
=
2
,
is_training
=
True
,
examples_consume
=
4
)
...
...
official/vision/beta/ops/mask_ops.py
View file @
59d3d2a3
...
...
@@ -16,7 +16,7 @@
import
math
# Import libraries
from
cvx2
import
latest
as
cv2
import
cv2
import
numpy
as
np
...
...
official/vision/beta/tasks/__init__.py
View file @
59d3d2a3
...
...
@@ -18,4 +18,3 @@
from
official.vision.beta.tasks
import
image_classification
from
official.vision.beta.tasks
import
maskrcnn
from
official.vision.beta.tasks
import
retinanet
from
official.vision.beta.tasks
import
video_classification
official/vision/beta/tasks/maskrcnn.py
View file @
59d3d2a3
...
...
@@ -69,11 +69,11 @@ class MaskRCNNTask(base_task.Task):
# Restoring checkpoint.
if
self
.
task_config
.
init_checkpoint_modules
==
'all'
:
ckpt
=
tf
.
train
.
Checkpoint
(
**
model
.
checkpoint_items
)
status
=
ckpt
.
re
ad
(
ckpt_dir_or_file
)
status
=
ckpt
.
re
store
(
ckpt_dir_or_file
)
status
.
assert_consumed
()
elif
self
.
task_config
.
init_checkpoint_modules
==
'backbone'
:
ckpt
=
tf
.
train
.
Checkpoint
(
backbone
=
model
.
backbone
)
status
=
ckpt
.
re
ad
(
ckpt_dir_or_file
)
status
=
ckpt
.
re
store
(
ckpt_dir_or_file
)
status
.
expect_partial
().
assert_existing_objects_matched
()
else
:
assert
"Only 'all' or 'backbone' can be used to initialize the model."
...
...
official/vision/beta/tasks/maskrcnn_test.py
View file @
59d3d2a3
...
...
@@ -43,9 +43,9 @@ class RetinaNetTaskTest(parameterized.TestCase, tf.test.TestCase):
config
.
task
.
model
.
input_size
=
[
384
,
384
,
3
]
config
.
train_steps
=
2
config
.
task
.
train_data
.
shuffle_buffer_size
=
10
config
.
task
.
train_data
.
input_path
=
"
/readahead/200M/placer/prod/home/snaggletooth/test/data/
coco/train-00000-of-00256.tfrecord"
config
.
task
.
train_data
.
input_path
=
"coco/train-00000-of-00256.tfrecord"
config
.
task
.
validation_data
.
global_batch_size
=
2
config
.
task
.
validation_data
.
input_path
=
"
/readahead/200M/placer/prod/home/snaggletooth/test/data/
coco/val-00000-of-00032.tfrecord"
config
.
task
.
validation_data
.
input_path
=
"coco/val-00000-of-00032.tfrecord"
task
=
maskrcnn
.
MaskRCNNTask
(
config
.
task
)
model
=
task
.
build_model
()
...
...
official/vision/beta/tasks/retinanet.py
View file @
59d3d2a3
...
...
@@ -69,11 +69,11 @@ class RetinaNetTask(base_task.Task):
# Restoring checkpoint.
if
self
.
task_config
.
init_checkpoint_modules
==
'all'
:
ckpt
=
tf
.
train
.
Checkpoint
(
**
model
.
checkpoint_items
)
status
=
ckpt
.
re
ad
(
ckpt_dir_or_file
)
status
=
ckpt
.
re
store
(
ckpt_dir_or_file
)
status
.
assert_consumed
()
elif
self
.
task_config
.
init_checkpoint_modules
==
'backbone'
:
ckpt
=
tf
.
train
.
Checkpoint
(
backbone
=
model
.
backbone
)
status
=
ckpt
.
re
ad
(
ckpt_dir_or_file
)
status
=
ckpt
.
re
store
(
ckpt_dir_or_file
)
status
.
expect_partial
().
assert_existing_objects_matched
()
else
:
assert
"Only 'all' or 'backbone' can be used to initialize the model."
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment