当前位置: 首页>>代码示例>>Python>>正文


Python Engine.forward方法代码示例

本文整理汇总了Python中engine.Engine.forward方法的典型用法代码示例。如果您正苦于以下问题:Python Engine.forward方法的具体用法?Python Engine.forward怎么用?Python Engine.forward使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在engine.Engine的用法示例。


在下文中一共展示了Engine.forward方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Car

# 需要导入模块: from engine import Engine [as 别名]
# 或者: from engine.Engine import forward [as 别名]
class Car(object):

    # constructor
    def __init__(self):
        config = ConfigParser()
        config.sections()
        config.read('config.ini')
        self.engineLeft = Engine(config.getint('EngineLeft', 'A'), config.getint('EngineLeft', 'B'), config.getint('EngineLeft', 'E'), 'EngineLeft')
        self.engineRight = Engine(config.getint('EngineRight', 'A'), config.getint('EngineRight', 'B'), config.getint('EngineRight', 'E'), 'EngineRight')

    # stop engine
    def stop(self): 
        self.engineLeft.stop()
        self.engineRight.stop()

    # drive forward
    def forward(self, speed):
        self.engineLeft.forward(speed)
        self.engineRight.forward(speed)

    # drive backward
    def backward(self, speed):
        self.engineLeft.backward(speed)
        self.engineRight.backward(speed)

    # turn right
    def turnRight(self, turn):
        self.engineRight.setTurn(turn)
    
    # turn left
    def turnLeft(self, turn):
        self.engineLeft.setTurn(turn)
        
开发者ID:gratbrav,项目名称:gratcar,代码行数:34,代码来源:car.py

示例2: main

# 需要导入模块: from engine import Engine [as 别名]
# 或者: from engine.Engine import forward [as 别名]
def main():
    parser = argparse.ArgumentParser(description='testing script')
    parser.add_argument('--data', type=str, default='data/negotiate',
        help='location of the data corpus')
    parser.add_argument('--unk_threshold', type=int, default=20,
        help='minimum word frequency to be in dictionary')
    parser.add_argument('--model_file', type=str,
        help='pretrained model file')
    parser.add_argument('--seed', type=int, default=1,
        help='random seed')
    parser.add_argument('--hierarchical', action='store_true', default=False,
        help='use hierarchical model')
    parser.add_argument('--bsz', type=int, default=16,
        help='batch size')
    parser.add_argument('--cuda', action='store_true', default=False,
        help='use CUDA')
    args = parser.parse_args()

    device_id = utils.use_cuda(args.cuda)
    utils.set_seed(args.seed)

    corpus = data.WordCorpus(args.data, freq_cutoff=args.unk_threshold, verbose=True)
    model = utils.load_model(args.model_file)

    crit = Criterion(model.word_dict, device_id=device_id)
    sel_crit = Criterion(model.item_dict, device_id=device_id,
        bad_toks=['<disconnect>', '<disagree>'])


    testset, testset_stats = corpus.test_dataset(args.bsz, device_id=device_id)
    test_loss, test_select_loss = 0, 0

    N = len(corpus.word_dict)
    for batch in testset:
        # run forward on the batch, produces output, hidden, target,
        # selection output and selection target
        out, hid, tgt, sel_out, sel_tgt = Engine.forward(model, batch, volatile=False)

        # compute LM and selection losses
        test_loss += tgt.size(0) * crit(out.view(-1, N), tgt).data[0]
        test_select_loss += sel_crit(sel_out, sel_tgt).data[0]

    test_loss /= testset_stats['nonpadn']
    test_select_loss /= len(testset)
    print('testloss %.3f | testppl %.3f' % (test_loss, np.exp(test_loss)))
    print('testselectloss %.3f | testselectppl %.3f' % (test_select_loss, np.exp(test_select_loss)))
开发者ID:mrunzo,项目名称:end-to-end-negotiator,代码行数:48,代码来源:test.py


注:本文中的engine.Engine.forward方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。