White Papers
14 CheXNet – Inference with Nvidia T4 on Dell EMC PowerEdge R7425 | Document ID
In this case, the architecture of an existing official network was used as base model
(resnet_v2_50). The output of the model is defined by a layer with 14 neurons to predict each
class. Since X-ray images can show more than one pathology, the model should also detect
multiple classifications; to do so, we used the sigmoid activation function. See the snippet
code below:
def model_fn(features, labels, mode, params):
tf.summary.image('images', features, max_outputs=6)
model = resnet_model.imagenet_resnet_v2(50, _NUM_CLASSES, params['data_format'])
logits = model(features, mode == tf.estimator.ModeKeys.TRAIN)
probs = tf.sigmoid(logits)
predictions = tf.argmax(logits, axis=1)
Restoring checkpoints from pre-trained model:
The variable checkpoint file holds the os.path with the directory where the pretrained model
with the ImageNet dataset ResNet-50_v2 (fp32) was stored, which was previously
downloaded from the official TensorFlow repository to the local host [6]. The model was
downloaded in the form of checkpoints produced by estimator during official training, then
the estimator initializes the weights from there.
if not tf.train.latest_checkpoint(FLAGS.model_dir):
vars_to_restore = [var for var in tf.global_variables() if 'dense' not in var.name]
checkpoint_file = os.path.join(FLAGS.pretrained_model_dir,
tf.train.latest_checkpoint(FLAGS.pretrained_model_dir))
latest_ckp = tf.train.latest_checkpoint(checkpoint_file)
tf.train.init_from_checkpoint(checkpoint_file,
{var.name.split(':')[0]: var for var in vars_to_restore})
Each subsequent call to the Estimator's train, evaluate, or predict method causes TensorFlow
rebuilds the model. See the Figure 7