Python models 模块,__dict__() 实例源码

我们从Python开源项目中,提取了以下3个代码示例,用于说明如何使用models.__dict__()

项目:homingbot    作者:homingbot    | 项目源码 | 文件源码
def setup():
    auth_provider = PlainTextAuthProvider(username=config.cassandra_user, password=config.cassandra_password)
    res = None
    if config.dev_mode:
        res = connection.setup(config.cassandra_hosts, config.cassandra_keyspace, protocol_version=3)
    else:
        logger.info("Using cert: %s", config.cassandra_client_cert)
        logger.info("Using key: %s", config.cassandra_client_key)

        res = connection.setup(
            config.cassandra_hosts,
            config.cassandra_keyspace,
            protocol_version=3,
            auth_provider=auth_provider,
            ssl_options={
                'keyfile': config.cassandra_client_key,
                'certfile': config.cassandra_client_cert,
                'ssl_version': ssl.PROTOCOL_TLSv1,
            }
        )
    print(res)
    if (config.dev_mode):
        management.create_keyspace_simple(config.cassandra_keyspace, 1)
        logger.debug("Processing tables...")
        for module, _ in inspect.getmembers(models, inspect.ismodule):
            for name, model in inspect.getmembers(models.__dict__[module], inspect.isclass):
                if not model.__dict__.get('__ignore__', False) and issubclass(model, BaseModel.Model):
                    logger.debug("Syncing table %s", name)
                    management.sync_table(model)
    logger.info("Successfully setup Cassandra!")
项目:two-stream-pytorch    作者:bryanyzhu    | 项目源码 | 文件源码
def build_model():

    model_name = args.modality + "_" + args.arch
    model = models.__dict__[model_name](pretrained=True, num_classes=101)
    if args.arch.startswith('alexnet') or args.arch.startswith('vgg'):
        model.features = torch.nn.DataParallel(model.features)
        model.cuda()
    else:
        model = torch.nn.DataParallel(model).cuda()
    return model
项目:two-stream-pytorch    作者:bryanyzhu    | 项目源码 | 文件源码
def build_model():

    model = models.__dict__[args.arch](pretrained=True, num_classes=101)
    model.cuda()
    return model