本文整理匯總了Python中net.Net.build方法的典型用法代碼示例。如果您正苦於以下問題:Python Net.build方法的具體用法?Python Net.build怎麽用?Python Net.build使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類net.Net
的用法示例。
在下文中一共展示了Net.build方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: predict
# 需要導入模塊: from net import Net [as 別名]
# 或者: from net.Net import build [as 別名]
def predict(weights_path, image_path):
'''
Function: loads a trained model and predicts the class of given image
Input: weights_path (.h5 file, prefer adding absolute path)
image_path (image to predict, prefer adding absolute path)
Returns: none
'''
model = Net.build(32, 32, 3, weights_path)
image = load_image(image_path, show=True) # load image, rescale to 0 to 1
class_ = model.predict(image) # predict the output, returns 36 length array
print("Detected: ", class_[0]) # print what is predicted
output_indice = -1 # set it initially to -1
# get class index having maximum predicted score
for i in range(36):
if(i == 0):
max = class_[0][i]
output_indice = 0
else:
if(class_[0][i] > max):
max = class_[0][i]
output_indice = i
# append 26 characters (A to Z) to list characters
characters = []
for i in range(65, 65+26):
characters.append(chr(i))
# if output indice > 9 (means characters)
if(output_indice > 9):
final_result = characters[(output_indice - 9) - 1]
print("Predicted: ", final_result)
print("value: ", max) # print predicted score
# else it's a digit, print directly
else:
print("Predicted: ", output_indice)
print("value: ", max) # print it's predicted score
示例2: print
# 需要導入模塊: from net import Net [as 別名]
# 或者: from net.Net import build [as 別名]
# Dimensions of our images
img_width, img_height = 32, 32
# 3 channel image
no_of_channels = 3
# train data Directory
train_data_dir = 'train/'
# test data Directory
validation_data_dir = 'test/'
epochs = 80
batch_size = 32
#initialize model
model = Net.build(width = img_width, height = img_height, depth = no_of_channels)
print('building done')
# Compile model
rms = optimizers.RMSprop(lr=0.001, rho=0.9, epsilon=None, decay=0.0)
print('optimizing done')
model.compile(loss='categorical_crossentropy',
optimizer=rms,
metrics=['accuracy'])
print('compiling')
# this is the augmentation configuration used for training
# horizontal_flip = False, as we need to retain Characters
train_datagen = ImageDataGenerator(
featurewise_center=True,