model1 = load_model('/path/to/weights')
model1.compile(loss='categorical_crossentropy', optimizer='sgd', metrics=['accuracy'])
model2 = load_model('/path/to/weights')
model2.compile(loss='categorical_crossentropy', optimizer='sgd', metrics=['accuracy'])
img = Image.open('/path/to/image')
img = img.convert('RGB')
x = np.asarray(img, dtype='float32')
x = x.transpose(2, 0, 1)
x = np.expand_dims(x, axis=0)
out1 = model1.predict(x)
print(np.argmax(out1))
> 0
out2 = model2.predict(x)
print(np.argmax(out2))
> 9
--
You received this message because you are subscribed to the Google Groups "Keras-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to keras-users...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/keras-users/18adf4d1-3502-4f2b-91b4-4d0fbfcab8a7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
def load_model(weights_path, num_classes=10):
model = Sequential()
model.add(ZeroPadding2D((1,1), input_shape=(3,224,224)))
model.add(Convolution2D(64, 3, 3, activation='relu'))
model.add(ZeroPadding2D((1,1)))
model.add(Convolution2D(64, 3, 3, activation='relu'))
model.add(MaxPooling2D((2,2), strides=(2,2)))
model.add(ZeroPadding2D((1,1)))
model.add(Convolution2D(128, 3, 3, activation='relu'))
model.add(ZeroPadding2D((1,1)))
model.add(Convolution2D(128, 3, 3, activation='relu'))
model.add(MaxPooling2D((2,2), strides=(2,2)))
model.add(ZeroPadding2D((1,1)))
model.add(Convolution2D(256, 3, 3, activation='relu'))
model.add(ZeroPadding2D((1,1)))
model.add(Convolution2D(256, 3, 3, activation='relu'))
model.add(ZeroPadding2D((1,1)))
model.add(Convolution2D(256, 3, 3, activation='relu'))
model.add(MaxPooling2D((2,2), strides=(2,2)))
model.add(ZeroPadding2D((1,1)))
model.add(Convolution2D(512, 3, 3, activation='relu'))
model.add(ZeroPadding2D((1,1)))
model.add(Convolution2D(512, 3, 3, activation='relu'))
model.add(ZeroPadding2D((1,1)))
model.add(Convolution2D(512, 3, 3, activation='relu'))
model.add(MaxPooling2D((2,2), strides=(2,2)))
model.add(ZeroPadding2D((1,1)))
model.add(Convolution2D(512, 3, 3, activation='relu'))
model.add(ZeroPadding2D((1,1)))
model.add(Convolution2D(512, 3, 3, activation='relu'))
model.add(ZeroPadding2D((1,1)))
model.add(Convolution2D(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(Dense(4096, activation='relu'))
model.add(Dropout(0.5))
# VGG16 above
# Now remove last FC layer and replace by your own output layer
model.layers.pop()
model.layers.pop()
model.add(Dense(num_classes, activation='softmax'))
model.load_weights(weights_path)
for layer in model.layers[:10]:
layer.trainable = False
return model
generator = ImageDataGenerator() # Where I specify some augmentation parameters
inputs = generator.flow_from_directory(
'/path/to/source_dir/',
target_size=(224, 224),
color_mode='rgb',
batch_size=16,
class_mode='categorical',
shuffle=True)
--
You received this message because you are subscribed to the Google Groups "Keras-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to keras-users...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/keras-users/939f1987-36db-4387-b844-347e9d5d317c%40googlegroups.com.
out1
> array([[ 1.87165151e-05, 8.84232186e-17, 2.62140153e-34,
2.05315212e-22, 6.29821518e-25, 2.11711216e-24,
1.95507500e-32, 1.44736917e-30, 4.60744398e-13,
9.99981284e-01]])
out2
> array([[ 9.94905829e-01, 1.57839488e-11, 9.36652955e-35,
7.26868101e-22, 1.22291198e-20, 3.31008678e-19,
1.29003039e-23, 2.60989331e-30, 6.66653650e-05,
5.02748974e-03]])
To view this discussion on the web, visit https://groups.google.com/d/msgid/keras-users/d85cb86f-b464-4511-978e-a99d5808ce46%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "Keras-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to keras-users...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/keras-users/8909a13a-380a-484f-b8bf-d39629d8b9b9%40googlegroups.com.