コード例 #1
0
                             kernel_regularizer=l2(weight_decay),
                             name='Classes')(flatten)
outputs = keras.layers.Activation('softmax', name='Output')(classes)
model = keras.models.Model(inputs=inputs, outputs=outputs)
optimizer = keras.optimizers.SGD(lr=0.001,
                                 decay=0,
                                 momentum=0.9,
                                 nesterov=False)
model.compile(optimizer=optimizer,
              loss='categorical_crossentropy',
              metrics=['accuracy'])

if cfg_type == ATTENTIONX:
    pretrained_model = '%s/isogr_rgb_attenxclstm_weights.h5' % model_prefix
elif cfg_type == ATTENTIONI:
    pretrained_model = '%s/isogr_rgb_atteniclstm_weights.h5' % model_prefix
elif cfg_type == ATTENTIONO:
    pretrained_model = '%s/isogr_rgb_attenoclstm_weights.h5' % model_prefix
print 'Loading pretrained model from %s' % pretrained_model
model.load_weights(pretrained_model, by_name=False)
for i in range(len(model.trainable_weights)):
    print model.trainable_weights[i]

_, test_labels = data.load_iso_video_list(testing_datalist)
test_steps = len(test_labels) / batch_size
print model.evaluate_generator(
    isoTestImageGenerator(testing_datalist, batch_size, seq_len, num_classes,
                          cfg_modality),
    steps=test_steps,
)
コード例 #2
0
model_prefix = './models/'
model_prefix = '/raid/gmzhu/tensorflow/ConvLSTMForGR/models/'
  
inputs = keras.layers.Input(shape=(seq_len, 112, 112, 3),
                            batch_shape=(batch_size, seq_len, 112, 112, 3))
feature = res3d_aclstm_mobilenet(inputs, seq_len, weight_decay, cfg_type)
flatten = keras.layers.Flatten(name='Flatten')(feature)
classes = keras.layers.Dense(num_classes, activation='linear', kernel_initializer='he_normal',
                    kernel_regularizer=l2(weight_decay), name='Classes')(flatten)
outputs = keras.layers.Activation('softmax', name='Output')(classes)
model = keras.models.Model(inputs=inputs, outputs=outputs)
optimizer = keras.optimizers.SGD(lr=0.001, decay=0, momentum=0.9, nesterov=False)
model.compile(optimizer=optimizer, loss='categorical_crossentropy', metrics=['accuracy'])

if cfg_type==ATTENTIONX:
  pretrained_model = '%s/isogr_rgb_attenxclstm_weights.h5'%model_prefix
elif cfg_type==ATTENTIONI:
  pretrained_model = '%s/isogr_rgb_atteniclstm_weights.h5'%model_prefix
elif cfg_type==ATTENTIONO:
  pretrained_model = '%s/isogr_rgb_attenoclstm_weights.h5'%model_prefix
print 'Loading pretrained model from %s' % pretrained_model
model.load_weights(pretrained_model, by_name=False)
for i in range(len(model.trainable_weights)):
  print model.trainable_weights[i]

_,test_labels = data.load_iso_video_list(testing_datalist)
test_steps = len(test_labels)/batch_size
print model.evaluate_generator(isoTestImageGenerator(testing_datalist, batch_size, seq_len, num_classes, cfg_modality),
                         steps=test_steps,
                         )