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
1308a574
Commit
1308a574
authored
Oct 30, 2020
by
Abdullah Rashwan
Committed by
A. Unique TensorFlower
Oct 30, 2020
Browse files
Internal change
PiperOrigin-RevId: 339917189
parent
7cda51fa
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
1 deletion
+28
-1
official/vision/beta/configs/image_classification.py
official/vision/beta/configs/image_classification.py
+3
-1
official/vision/beta/tasks/image_classification.py
official/vision/beta/tasks/image_classification.py
+25
-0
No files found.
official/vision/beta/configs/image_classification.py
View file @
1308a574
...
@@ -15,7 +15,7 @@
...
@@ -15,7 +15,7 @@
# ==============================================================================
# ==============================================================================
"""Image classification configuration definition."""
"""Image classification configuration definition."""
import
os
import
os
from
typing
import
List
from
typing
import
List
,
Optional
import
dataclasses
import
dataclasses
from
official.core
import
config_definitions
as
cfg
from
official.core
import
config_definitions
as
cfg
from
official.core
import
exp_factory
from
official.core
import
exp_factory
...
@@ -63,6 +63,8 @@ class ImageClassificationTask(cfg.TaskConfig):
...
@@ -63,6 +63,8 @@ class ImageClassificationTask(cfg.TaskConfig):
validation_data
:
DataConfig
=
DataConfig
(
is_training
=
False
)
validation_data
:
DataConfig
=
DataConfig
(
is_training
=
False
)
losses
:
Losses
=
Losses
()
losses
:
Losses
=
Losses
()
gradient_clip_norm
:
float
=
0.0
gradient_clip_norm
:
float
=
0.0
init_checkpoint
:
Optional
[
str
]
=
None
init_checkpoint_modules
:
str
=
'all'
# all or backbone
@
exp_factory
.
register_config_factory
(
'image_classification'
)
@
exp_factory
.
register_config_factory
(
'image_classification'
)
...
...
official/vision/beta/tasks/image_classification.py
View file @
1308a574
...
@@ -14,6 +14,7 @@
...
@@ -14,6 +14,7 @@
# limitations under the License.
# limitations under the License.
# ==============================================================================
# ==============================================================================
"""Image classification task definition."""
"""Image classification task definition."""
from
absl
import
logging
import
tensorflow
as
tf
import
tensorflow
as
tf
from
official.core
import
base_task
from
official.core
import
base_task
from
official.core
import
input_reader
from
official.core
import
input_reader
...
@@ -46,6 +47,30 @@ class ImageClassificationTask(base_task.Task):
...
@@ -46,6 +47,30 @@ class ImageClassificationTask(base_task.Task):
l2_regularizer
=
l2_regularizer
)
l2_regularizer
=
l2_regularizer
)
return
model
return
model
def
initialize
(
self
,
model
:
tf
.
keras
.
Model
):
"""Loading pretrained checkpoint."""
if
not
self
.
task_config
.
init_checkpoint
:
return
ckpt_dir_or_file
=
self
.
task_config
.
init_checkpoint
if
tf
.
io
.
gfile
.
isdir
(
ckpt_dir_or_file
):
ckpt_dir_or_file
=
tf
.
train
.
latest_checkpoint
(
ckpt_dir_or_file
)
# Restoring checkpoint.
if
self
.
task_config
.
init_checkpoint_modules
==
'all'
:
ckpt
=
tf
.
train
.
Checkpoint
(
**
model
.
checkpoint_items
)
status
=
ckpt
.
restore
(
ckpt_dir_or_file
)
status
.
assert_consumed
()
elif
self
.
task_config
.
init_checkpoint_modules
==
'backbone'
:
ckpt
=
tf
.
train
.
Checkpoint
(
backbone
=
model
.
backbone
)
status
=
ckpt
.
restore
(
ckpt_dir_or_file
)
status
.
expect_partial
().
assert_existing_objects_matched
()
else
:
assert
"Only 'all' or 'backbone' can be used to initialize the model."
logging
.
info
(
'Finished loading pretrained checkpoint from %s'
,
ckpt_dir_or_file
)
def
build_inputs
(
self
,
params
,
input_context
=
None
):
def
build_inputs
(
self
,
params
,
input_context
=
None
):
"""Builds classification input."""
"""Builds classification input."""
...
...
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