本文整理匯總了Python中resnet50.ResNet50方法的典型用法代碼示例。如果您正苦於以下問題:Python resnet50.ResNet50方法的具體用法?Python resnet50.ResNet50怎麽用?Python resnet50.ResNet50使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類resnet50
的用法示例。
在下文中一共展示了resnet50.ResNet50方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: predict
# 需要導入模塊: import resnet50 [as 別名]
# 或者: from resnet50 import ResNet50 [as 別名]
def predict(filename):
assert os.path.isfile(filename) and 'cannot find file'
model = ResNet50(weights='imagenet')
img = image.load_img(filename, target_size=(224, 224))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)
preds = decode_predictions(model.predict(x))
if len(preds) == 0:
return None
return preds[0][0][1]
##################################
# main
##################################
示例2: predict
# 需要導入模塊: import resnet50 [as 別名]
# 或者: from resnet50 import ResNet50 [as 別名]
def predict(filename):
assert os.path.isfile(filename) and 'cannot find file'
model = ResNet50(weights='imagenet')
img = image.load_img(filename, target_size=(224, 224))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)
preds = decode_predictions(model.predict(x))
if len(preds) == 0:
return None
return preds[0][0][1]
##################################
# config
##################################
示例3: predict
# 需要導入模塊: import resnet50 [as 別名]
# 或者: from resnet50 import ResNet50 [as 別名]
def predict(path, model_path, index_file_path, MainUI):
try:
result_string = " Detected Object : Probability \n \n"
# Making check to load Model
if (MainUI.resnet_model_loaded == False):
wx.CallAfter(pub.sendMessage, "report101", message="Loading ResNet model for the first time. This may take a few minutes or less than a minute. Please wait. \nLoading.....")
model = ResNet50(include_top=True, weights="imagenet", model_path=model_path)
wx.CallAfter(pub.sendMessage, "report101", message="ResNet model loaded.. Picture about to be processed.. \nLoading......")
MainUI.model_collection_resnet.append(model) # Loading model if not loaded yet
MainUI.resnet_model_loaded = True
else:
wx.CallAfter(pub.sendMessage, "report101", message="Retrieving loaded model. \nLoading........")
model = MainUI.model_collection_resnet[0] # Getting Model from model array if loaded before
wx.CallAfter(pub.sendMessage, "report101", message="ResNet model loaded.. Picture about to be processed.. \nLoading......")
# Image prediction processing
target_image = image.load_img(path, grayscale=False, target_size=(224, 224))
target_image = image.img_to_array(target_image, data_format="channels_last")
target_image = np.expand_dims(target_image, axis=0)
target_image = preprocess_input(target_image, data_format="channels_last")
wx.CallAfter(pub.sendMessage, "report101", message="Picture is transformed for prediction. \nLoading........")
prediction = model.predict(x=target_image, steps=1)
wx.CallAfter(pub.sendMessage, "report101", message="Picture prediction is done. Sending in results. \nLoading......")
# Retrieving prediction result and sending it back to the thread
prediction_result = decode_predictions(prediction, top=10, index_file_path=index_file_path)
for results in prediction_result:
countdown = 0
for result in results:
countdown += 1
result_string += "(" + str(countdown) + ") " + str(result[1]) + " : " + str(100 * result[2])[
0:4] + "% \n"
return result_string
except Exception as e:
return getattr(e, "message", repr(e))
示例4: finetuned_resnet
# 需要導入模塊: import resnet50 [as 別名]
# 或者: from resnet50 import ResNet50 [as 別名]
def finetuned_resnet(include_top, weights_dir):
'''
:param include_top: True for training, False for generating intermediate results for
LSTM cell
:param weights_dir: path to load finetune_resnet.h5
:return:
'''
base_model = ResNet50(include_top=False, weights='imagenet', input_shape=IMSIZE)
for layer in base_model.layers:
layer.trainable = False
x = base_model.output
x = Flatten()(x)
x = Dense(2048, activation='relu')(x)
x = Dropout(0.5)(x)
x = Dense(1024, activation='relu')(x)
x = Dropout(0.5)(x)
if include_top:
x = Dense(N_CLASSES, activation='softmax')(x)
model = Model(inputs=base_model.input, outputs=x)
if os.path.exists(weights_dir):
model.load_weights(weights_dir, by_name=True)
return model
示例5: main
# 需要導入模塊: import resnet50 [as 別名]
# 或者: from resnet50 import ResNet50 [as 別名]
def main():
archs = {
'alex': alex.Alex,
'nin': nin.NIN,
'resnet50': resnet50.ResNet50,
}
parser = argparse.ArgumentParser(
description='Learning convnet from ILSVRC2012 dataset')
parser.add_argument('--arch', '-a', choices=archs.keys(),
default='resnet50',
help='Convnet architecture')
parser.add_argument('--train', default='',
help='Path to training image-label list file')
parser.add_argument('--val', default='',
help='Path to validation image-label list file')
parser.add_argument('--batchsize', '-B', type=int, default=32,
help='Learning minibatch size')
parser.add_argument('--epoch', '-E', type=int, default=10,
help='Number of epochs to train')
parser.add_argument('--frequency', '-f', type=int, default=-1,
help='Frequency of taking a snapshot')
parser.add_argument('--gpu', '-g', type=int, default=-1,
help='GPU ID (negative value indicates CPU')
parser.add_argument('--initmodel',
help='Initialize the model from given file')
parser.add_argument('--loaderjob', '-j', type=int,
help='Number of parallel data loading processes')
parser.add_argument('--mean', '-m', default='mean.npy',
help='Mean file (computed by compute_mean.py)')
parser.add_argument('--noplot', dest='plot', action='store_false',
help='Disable PlotReport extension')
parser.add_argument('--resume', '-r', default='',
help='Initialize the trainer from given file')
parser.add_argument('--out', '-o', default='result',
help='Output directory')
parser.add_argument('--root', '-R', default='.',
help='Root directory path of image files')
parser.add_argument('--val_batchsize', '-b', type=int, default=250,
help='Validation minibatch size')
parser.add_argument('--test', action='store_true')
parser.add_argument('--run_training', action='store_true',
help='Run training')
parser.set_defaults(test=False)
args = parser.parse_args()
model_cls = archs[args.arch]
main_impl(args, model_cls)
# TODO(hamaji): Stop writing a file to scripts.
with open('scripts/%s_stamp' % args.arch, 'w'): pass