keras-team / keras-applications

Reference implementations of popular deep learning models.
Other
2k stars 910 forks source link

Enable MobileNet and V2 for `channels_first` #96

Closed taehoonlee closed 5 years ago

taehoonlee commented 5 years ago

This PR enables MobileNet and V2 for channels_first.

taehoonlee commented 5 years ago

Test codes:

import numpy as np
import tensornets as nets

from keras import backend as K
from keras.applications.mobilenet import MobileNet
from keras.applications.mobilenet import preprocess_input, decode_predictions

img = nets.utils.load_img('cat.png', target_size=256, crop_size=224)

model = MobileNet(weights='imagenet')
preds = model.predict(preprocess_input(img))

print(decode_predictions(preds, top=3)[0])

K.set_image_data_format('channels_first')

model2 = MobileNet(weights='imagenet')
preds = model2.predict(np.transpose(img, (0, 3, 1, 2)))

print(decode_predictions(preds, top=3)[0])

The results: