18739-hws/hw3/models.py
def vgg_16_imagenet(weights='models/vgg16_weights_th_dim_ordering_th_kernels.h5'):
    '''
    Loads a pre-trained imagenet model, using the weights specified (optional).
    To get a model with the weights uninitialized, pass in None for weights.
    '''

    model = Sequential()
    model.add(ZeroPadding2D((1,1), input_shape=(3,224,224)))
    model.add(Conv2D(64, (3, 3), activation='relu'))
    model.add(ZeroPadding2D((1,1)))
    model.add(Conv2D(64, (3, 3), activation='relu'))
    model.add(MaxPooling2D((2,2), strides=(2,2)))

    model.add(ZeroPadding2D((1,1)))
    model.add(Conv2D(128, (3, 3), activation='relu'))
    model.add(ZeroPadding2D((1,1)))
    model.add(Conv2D(128, (3, 3), activation='relu'))
    model.add(MaxPooling2D((2,2), strides=(2,2)))

    model.add(ZeroPadding2D((1,1)))
    model.add(Conv2D(256, (3, 3), activation='relu'))
    model.add(ZeroPadding2D((1,1)))
    model.add(Conv2D(256, (3, 3), activation='relu'))
    model.add(ZeroPadding2D((1,1)))
    model.add(Conv2D(256, (3, 3), activation='relu'))
    model.add(MaxPooling2D((2,2), strides=(2,2)))

    model.add(ZeroPadding2D((1,1)))
    model.add(Conv2D(512, (3, 3), activation='relu'))
    model.add(ZeroPadding2D((1,1)))
    model.add(Conv2D(512, (3, 3), activation='relu'))
    model.add(ZeroPadding2D((1,1)))
    model.add(Conv2D(512, (3, 3), activation='relu'))
    model.add(MaxPooling2D((2,2), strides=(2,2)))

    model.add(ZeroPadding2D((1,1)))
    model.add(Conv2D(512, (3, 3), activation='relu'))
    model.add(ZeroPadding2D((1,1)))
    model.add(Conv2D(512, (3, 3), activation='relu'))
    model.add(ZeroPadding2D((1,1)))
    model.add(Conv2D(512, (3, 3), activation='relu'))
    model.add(MaxPooling2D((2,2), strides=(2,2)))

    model.add(Flatten())
    model.add(Dense(4096, activation='relu'))
    #model.add(Dropout(0.5))
    model.add(Activation('linear'))
    model.add(Dense(4096, activation='relu'))
    #model.add(Dropout(0.5))
    model.add(Activation('linear'))
    model.add(Dense(1000, activation='linear'))

    if weights is not None:
        model.load_weights(weights)

    return model

    Loads a pre-trained imagenet model, using the weights specified (optional).
    To get a model with the weights uninitialized, pass in None for weights.
    
Loads a pre-trained imagenet model, using the weights specified (optional).
To get a model with the weights uninitialized, pass in None for weights.
Loads a pre - trained imagenet model using the weights specified ( optional ) . To get a model with the weights uninitialized pass in None for weights .
def vgg_16_imagenet(weights='models/vgg16_weights_th_dim_ordering_th_kernels.h5'):
    model = Sequential()
    model.add(ZeroPadding2D((1,1), input_shape=(3,224,224)))
    model.add(Conv2D(64, (3, 3), activation='relu'))
    model.add(ZeroPadding2D((1,1)))
    model.add(Conv2D(64, (3, 3), activation='relu'))
    model.add(MaxPooling2D((2,2), strides=(2,2)))
    model.add(ZeroPadding2D((1,1)))
    model.add(Conv2D(128, (3, 3), activation='relu'))
    model.add(ZeroPadding2D((1,1)))
    model.add(Conv2D(128, (3, 3), activation='relu'))
    model.add(MaxPooling2D((2,2), strides=(2,2)))
    model.add(ZeroPadding2D((1,1)))
    model.add(Conv2D(256, (3, 3), activation='relu'))
    model.add(ZeroPadding2D((1,1)))
    model.add(Conv2D(256, (3, 3), activation='relu'))
    model.add(ZeroPadding2D((1,1)))
    model.add(Conv2D(256, (3, 3), activation='relu'))
    model.add(MaxPooling2D((2,2), strides=(2,2)))
    model.add(ZeroPadding2D((1,1)))
    model.add(Conv2D(512, (3, 3), activation='relu'))
    model.add(ZeroPadding2D((1,1)))
    model.add(Conv2D(512, (3, 3), activation='relu'))
    model.add(ZeroPadding2D((1,1)))
    model.add(Conv2D(512, (3, 3), activation='relu'))
    model.add(MaxPooling2D((2,2), strides=(2,2)))
    model.add(ZeroPadding2D((1,1)))
    model.add(Conv2D(512, (3, 3), activation='relu'))
    model.add(ZeroPadding2D((1,1)))
    model.add(Conv2D(512, (3, 3), activation='relu'))
    model.add(ZeroPadding2D((1,1)))
    model.add(Conv2D(512, (3, 3), activation='relu'))
    model.add(MaxPooling2D((2,2), strides=(2,2)))
    model.add(Flatten())
    model.add(Dense(4096, activation='relu'))
    model.add(Activation('linear'))
    model.add(Dense(4096, activation='relu'))
    model.add(Activation('linear'))
    model.add(Dense(1000, activation='linear'))
    if weights is not None:
        model.load_weights(weights)
    return model
def vgg_16_imagenet ( weights = 'models/vgg16_weights_th_dim_ordering_th_kernels.h5' ) : model = Sequential ( ) model . add ( ZeroPadding2D ( ( 1 , 1 ) , input_shape = ( 3 , 224 , 224 ) ) ) model . add ( Conv2D ( 64 , ( 3 , 3 ) , activation = 'relu' ) ) model . add ( ZeroPadding2D ( ( 1 , 1 ) ) ) model . add ( Conv2D ( 64 , ( 3 , 3 ) , activation = 'relu' ) ) model . add ( MaxPooling2D ( ( 2 , 2 ) , strides = ( 2 , 2 ) ) ) model . add ( ZeroPadding2D ( ( 1 , 1 ) ) ) model . add ( Conv2D ( 128 , ( 3 , 3 ) , activation = 'relu' ) ) model . add ( ZeroPadding2D ( ( 1 , 1 ) ) ) model . add ( Conv2D ( 128 , ( 3 , 3 ) , activation = 'relu' ) ) model . add ( MaxPooling2D ( ( 2 , 2 ) , strides = ( 2 , 2 ) ) ) model . add ( ZeroPadding2D ( ( 1 , 1 ) ) ) model . add ( Conv2D ( 256 , ( 3 , 3 ) , activation = 'relu' ) ) model . add ( ZeroPadding2D ( ( 1 , 1 ) ) ) model . add ( Conv2D ( 256 , ( 3 , 3 ) , activation = 'relu' ) ) model . add ( ZeroPadding2D ( ( 1 , 1 ) ) ) model . add ( Conv2D ( 256 , ( 3 , 3 ) , activation = 'relu' ) ) model . add ( MaxPooling2D ( ( 2 , 2 ) , strides = ( 2 , 2 ) ) ) model . add ( ZeroPadding2D ( ( 1 , 1 ) ) ) model . add ( Conv2D ( 512 , ( 3 , 3 ) , activation = 'relu' ) ) model . add ( ZeroPadding2D ( ( 1 , 1 ) ) ) model . add ( Conv2D ( 512 , ( 3 , 3 ) , activation = 'relu' ) ) model . add ( ZeroPadding2D ( ( 1 , 1 ) ) ) model . add ( Conv2D ( 512 , ( 3 , 3 ) , activation = 'relu' ) ) model . add ( MaxPooling2D ( ( 2 , 2 ) , strides = ( 2 , 2 ) ) ) model . add ( ZeroPadding2D ( ( 1 , 1 ) ) ) model . add ( Conv2D ( 512 , ( 3 , 3 ) , activation = 'relu' ) ) model . add ( ZeroPadding2D ( ( 1 , 1 ) ) ) model . add ( Conv2D ( 512 , ( 3 , 3 ) , activation = 'relu' ) ) model . add ( ZeroPadding2D ( ( 1 , 1 ) ) ) model . add ( Conv2D ( 512 , ( 3 , 3 ) , activation = 'relu' ) ) model . add ( MaxPooling2D ( ( 2 , 2 ) , strides = ( 2 , 2 ) ) ) model . add ( Flatten ( ) ) model . add ( Dense ( 4096 , activation = 'relu' ) ) model . add ( Activation ( 'linear' ) ) model . add ( Dense ( 4096 , activation = 'relu' ) ) model . add ( Activation ( 'linear' ) ) model . add ( Dense ( 1000 , activation = 'linear' ) ) if weights is not None : model . load_weights ( weights ) return model
Loads a pre-trained imagenet model, using the weights specified (optional).
Loads a pre - trained imagenet model using the weights specified ( optional ) .
'''
    Loads a pre-trained imagenet model, using the weights specified (optional).
    To get a model with the weights uninitialized, pass in None for weights.
    ''' #model.add(Dropout(0.5)) #model.add(Dropout(0.5))
weights