本文整理汇总了Python中model.Model.train_model方法的典型用法代码示例。如果您正苦于以下问题:Python Model.train_model方法的具体用法?Python Model.train_model怎么用?Python Model.train_model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.Model
的用法示例。
在下文中一共展示了Model.train_model方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: keypoint_detection
# 需要导入模块: from model import Model [as 别名]
# 或者: from model.Model import train_model [as 别名]
def keypoint_detection():
try:
data = sio.loadmat('data.mat')
except:
load.csv()
data = sio.loadmat('data.mat')
train_x = data['train_x']
train_y = data['train_y']
test_x = data['test_x']
# data normalization
train_x = train_x / 256.0
train_y = (train_y - 48) / 48.0
test_x = test_x / 256.0
sklearn.utils.shuffle(train_x, train_y, random_state=0)
train_x, valid_x = train_x[:-400], train_x[-400:]
train_y, valid_y = train_y[:-400], train_y[-400:]
model = Model(0.01, 0.9, 0.0005, 100, 10000)
model.add_layer(layers.FullConnectedLayer(9216, 256, 1, layers.rectify))
model.add_layer(layers.DropoutLayer(0.5))
model.add_layer(layers.FullConnectedLayer(256, 100, 1, layers.rectify))
model.add_layer(layers.DropoutLayer(0.5))
model.add_layer(layers.FullConnectedLayer(100, 30))
model.set_loss_function(layers.EuclideanLoss)
model.build()
print 'build model complete'
model.train_model(train_x, train_y, valid_x, valid_y)
model.save_test_result(test_x)
示例2: keypoint_detection
# 需要导入模块: from model import Model [as 别名]
# 或者: from model.Model import train_model [as 别名]
def keypoint_detection():
try:
data = sio.loadmat('data.mat')
except:
load.csv()
data = sio.loadmat('data.mat')
train_x = data['train_x']
train_y = data['train_y']
test_x = data['test_x']
# data normalization
train_x = train_x / 256.0
train_y = (train_y - 48) / 48.0
test_x = test_x / 256.0
sklearn.utils.shuffle(train_x, train_y, random_state=0)
train_x, valid_x = train_x[:-400], train_x[-400:]
train_y, valid_y = train_y[:-400], train_y[-400:]
model = Model(0.01, 0.9, 0.0005, 100, 1000)
model.add_layer(layers.ReshapeLayer(1, 96, 96))
model.add_layer(layers.ConvolutionLayer((3, 3), 8, 1, 1, layers.rectify))
model.add_layer(layers.PoolingLayer((2, 2))) # 47 * 47 * 8
model.add_layer(layers.ConvolutionLayer((2, 2), 16, 8, 1, layers.rectify))
model.add_layer(layers.PoolingLayer((2, 2))) # 23 * 23 * 16
model.add_layer(layers.ConvolutionLayer((2, 2), 32, 16, 1, layers.rectify))
model.add_layer(layers.PoolingLayer((2, 2))) # 11 * 11 * 32
model.add_layer(layers.ConvolutionLayer((2, 2), 64, 32, 1, layers.rectify))
model.add_layer(layers.PoolingLayer((2, 2))) # 5 * 5 * 64
model.add_layer(layers.ConvolutionLayer((2, 2), 128, 64, 1, layers.rectify))
model.add_layer(layers.PoolingLayer((2, 2))) # 2 * 2 * 128
model.add_layer(layers.FullConnectedLayer(512, 512, 1, layers.rectify))
model.add_layer(layers.DropoutLayer(0.5))
model.add_layer(layers.FullConnectedLayer(512, 512, 1, layers.rectify))
model.add_layer(layers.DropoutLayer(0.5))
model.add_layer(layers.FullConnectedLayer(512, 30))
model.set_loss_function(layers.EuclideanLoss)
model.build()
print 'build model complete'
model.train_model(train_x, train_y, valid_x, valid_y)
model.save_test_result(test_x)
示例3: open
# 需要导入模块: from model import Model [as 别名]
# 或者: from model.Model import train_model [as 别名]
if args.file:
for i in args.file:
try:
with open(i) as fd:
texts.append(fd.read())
except Exception, exc:
print exc.strerror + ': ' + i
# read remote files to train model
if args.url:
for i in args.url:
proc = subprocess.Popen(["curl", i], stdout=subprocess.PIPE)
(out, err) = proc.communicate()
if err:
print err + ": " + i
if len(out) > 0:
texts.append(out)
if len(texts) == 0:
print "Error: no train text given"
exit()
model = Model(args.n)
for i in texts:
model.train_model(i)
# save model
with open(args.o, "wb") as fd:
pickle.dump(model, fd)
pass