-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathestimators.py
36 lines (29 loc) · 1.07 KB
/
estimators.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""Estimator wrapper for ResNet Keras models."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import tensorflow as tf
from models import build_resnet_model
def build_resnet_estimator(input_shape, n_classes,
depth=18, model_dir=None):
"""Build a TF Estimator instance for ResNet.
Args:
input_shape: (width, height, channel) of input images.
n_classes: Number of output classes.
depth: Depth of the model. Expected values are 18, 34, 50, 101 or 152.
model_dir: Directory to store parameters.
Returns:
ResNet TF Estimator.
"""
model = build_resnet_model(input_shape, n_classes,
depth=depth)
optimizer = tf.train.AdamOptimizer(learning_rate=0.001)
model.compile(optimizer=optimizer,
loss='categorical_crossentropy',
metrics=['accuracy']
)
estimator = tf.keras.estimator.model_to_estimator(
keras_model=model,
model_dir=model_dir,
)
return estimator