Learn practical skills, build real-world projects, and advance your career

AI for Medicine Course 1 Week 1 lecture exercises

Densenet

In this week's assignment, you'll be using a pre-trained Densenet model for image classification.

Densenet is a convolutional network where each layer is connected to all other layers that are deeper in the network

  • The first layer is connected to the 2nd, 3rd, 4th etc.
  • The second layer is connected to the 3rd, 4th, 5th etc.

Like this:

U-net Image

For a detailed explanation of Densenet, check out the source of the image above, a paper by Gao Huang et al. 2018 called Densely Connected Convolutional Networks.

The cells below are set up to provide an exploration of the Keras densenet implementation that you'll be using in the assignment. Run these cells to gain some insight into the network architecture.

# Import Densenet from Keras
from keras.applications.densenet import DenseNet121
from keras.layers import Dense, GlobalAveragePooling2D
from keras.models import Model
from keras import backend as K
Using TensorFlow backend.

For your work in the assignment, you'll be loading a set of pre-trained weights to reduce training time.

# Create the base pre-trained model
base_model = DenseNet121(weights='./nih/densenet.hdf5', include_top=False);
WARNING:tensorflow:From /opt/conda/lib/python3.6/site-packages/tensorflow_core/python/ops/resource_variable_ops.py:1630: calling BaseResourceVariable.__init__ (from tensorflow.python.ops.resource_variable_ops) with constraint is deprecated and will be removed in a future version. Instructions for updating: If using Keras pass *_constraint arguments to layers. WARNING:tensorflow:From /opt/conda/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:4070: The name tf.nn.max_pool is deprecated. Please use tf.nn.max_pool2d instead. WARNING:tensorflow:From /opt/conda/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:4074: The name tf.nn.avg_pool is deprecated. Please use tf.nn.avg_pool2d instead.