Closed taehoonlee closed 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:
MobileNet
[('n02124075', 'Egyptian_cat', 0.47201723), ('n03482405', 'hamper', 0.10415065), ('n02123045', 'tabby', 0.09730302)]
[('n02124075', 'Egyptian_cat', 0.472019), ('n03482405', 'hamper', 0.104150146), ('n02123045', 'tabby', 0.09730264)]
MobileNetV2
[('n02124075', 'Egyptian_cat', 0.16725165), ('n02123045', 'tabby', 0.12793817), ('n03482405', 'hamper', 0.12389358)]
[('n02124075', 'Egyptian_cat', 0.16725159), ('n02123045', 'tabby', 0.127938), ('n03482405', 'hamper', 0.12389337)]
Xception
[('n02123045', 'tabby', 0.17753284), ('n02124075', 'Egyptian_cat', 0.17632152), ('n03482405', 'hamper', 0.09113098)]
[('n02123045', 'tabby', 0.17753297), ('n02124075', 'Egyptian_cat', 0.17632148), ('n03482405', 'hamper', 0.09113101)]
This PR enables MobileNet and V2 for
channels_first
.