How to use extensions - 10 common examples

To help you get started, we’ve selected a few extensions examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github donnyyou / PyTorchCV / models / backbones / densenet / syncbn_densenet_models.py View on Github external
num_features = num_init_features
        for i, num_layers in enumerate(block_config):
            block = _DenseBlock(num_layers=num_layers, num_input_features=num_features,
                                bn_size=bn_size, growth_rate=growth_rate, drop_rate=drop_rate)
            self.features.add_module('denseblock%d' % (i + 1), block)
            num_features = num_features + num_layers * growth_rate
            if i != len(block_config) - 1:
                trans = _Transition(num_input_features=num_features, num_output_features=num_features // 2)
                avg_pool = nn.AvgPool2d(kernel_size=2, stride=2)
                self.features.add_module('transition%d' % (i + 1), trans)
                self.features.add_module('transition%s_pool' % (i + 1), avg_pool)
                num_features = num_features // 2

        self.num_features = num_features
        # Final batch norm
        self.features.add_module('norm5', BatchNorm2d(num_features))

        # Linear layer
        self.classifier = nn.Linear(num_features, num_classes)

        # Official init from torch repo.
        for m in self.modules():
            if isinstance(m, nn.Conv2d):
                nn.init.kaiming_normal_(m.weight)
            elif isinstance(m, BatchNorm2d):
                nn.init.constant_(m.weight, 1)
                nn.init.constant_(m.bias, 0)
            elif isinstance(m, nn.Linear):
                nn.init.constant_(m.bias, 0)
github donnyyou / PyTorchCV / models / seg / semantic / syncbn_gridencnet.py View on Github external
def __init__(self, in_channels, out_channels):
        super(FCNHead, self).__init__()
        inter_channels = in_channels // 4
        from extensions.layers.syncbn.module import BatchNorm2d
        self.conv5 = nn.Sequential(nn.Conv2d(in_channels, inter_channels, 3, padding=1, bias=False),
                                   BatchNorm2d(inter_channels),
                                   nn.ReLU(),
                                   nn.Dropout2d(0.1, False),
                                   nn.Conv2d(inter_channels, out_channels, 1))
github dlapiduz / govcode.org / models.py View on Github external
name = db.Column(db.String(100))
    username = db.Column(db.String(50), unique=True)
    slug = db.Column(db.String(100), unique=True)
    ignore = db.Column(db.Boolean, default=False)

    def __repr__(self):
        return '' % self.name

class Repository(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    gh_id = db.Column(db.Integer)
    name = db.Column(db.String(100))
    forks = db.Column(db.Integer)
    watchers = db.Column(db.Integer)
    size = db.Column(db.Integer)
    open_issues = db.Column(db.Integer)
    description = db.Column(db.Text)
    organization_id = db.Column(db.Integer, db.ForeignKey('organization.id'))
    organization = db.relationship('Organization',
        backref=db.backref('repositories', lazy='dynamic'))
    users = db.relationship("User", secondary="commit", backref="repositories")
    slug = db.Column(db.String(100), unique=True)
    last_commit_date = db.Column(db.DateTime)

    @hybrid_property
    def last_commit(self):
        return self.commits.order_by(desc(Commit.date)).first()

    def __repr__(self):
        return '' % self.name

class Commit(db.Model):
github pycook / cmdb / lib / ci.py View on Github external
def delete(self, ci_id):
        ci = db.session.query(CI).filter(CI.ci_id == ci_id).first()
        if ci is not None:
            attrs = db.session.query(CITypeAttribute.attr_id).filter(
                CITypeAttribute.type_id == ci.type_id).all()
            attr_names = []
            for attr in attrs:
                attr_names.append(CIAttributeCache.get(attr.attr_id).attr_name)
            attr_names = set(attr_names)
            for attr_name in attr_names:
                Table = TableMap(attr_name=attr_name).table
                db.session.query(Table).filter(Table.ci_id == ci_id).delete()
            db.session.query(CIRelation).filter(
                CIRelation.first_ci_id == ci_id).delete()
            db.session.query(CIRelation).filter(
                CIRelation.second_ci_id == ci_id).delete()
            # db.session.query(CIAttributeHistory).filter(
            #     CIAttributeHistory.ci_id == ci_id).delete()

            db.session.flush()
            db.session.delete(ci)
            try:
                db.session.commit()
            except Exception as e:
                db.session.rollback()
                current_app.logger.error("delete CI error, {0}".format(str(e)))
                return abort(400, "delete CI error, {0}".format(str(e)))
            # todo: write history
github pycook / cmdb / lib / attribute.py View on Github external
def delete(self, attr_id):
        attr, name = db.session.query(CIAttribute).filter_by(
            attr_id=attr_id).first(), None
        if attr:
            if attr.is_choice:
                choice_table = type_map["choice"].get(attr.value_type)
                db.session.query(choice_table).filter(
                    choice_table.attr_id == attr_id).delete()
                db.session.flush()
            name = attr.attr_name
            CIAttributeCache.clean(attr)
            db.session.delete(attr)
            try:
                db.session.commit()
            except Exception as e:
                db.session.rollback()
                current_app.logger.error("delete attribute error, {0}".format(
                    str(e)))
                return abort(500, str(e))
        else:
            return abort(404, "attribute you want to delete is not existed")
        return name
github pycook / cmdb / lib / ci.py View on Github external
def add_heartbeat(self, ci_type, unique):
        ci_type = CITypeCache.get(ci_type)
        if not ci_type:
            return 'error'
        uniq_key = CIAttributeCache.get(ci_type.uniq_id)
        Table = TableMap(attr_name=uniq_key.attr_name).table
        ci_id = db.session.query(Table.ci_id).filter(
            Table.attr_id == uniq_key.attr_id).filter(
                Table.value == unique).first()
        if ci_id is None:
            return 'error'
        ci = db.session.query(CI).filter(CI.ci_id == ci_id.ci_id).first()
        if ci is None:
            return 'error'

        ci.heartbeat = datetime.datetime.now()

        db.session.add(ci)
        db.session.commit()
        return "ok"
github openml / openml.org / server.py View on Github external
def signupfunc():
        if request.method == 'POST':
            robj = request.get_json()
            user = User(username=robj['name'], email=robj['email'])
            user.set_password(robj['password'])
            db.session.add(user)
            db.session.commit()

        return 'request'
github dlapiduz / govcode.org / models.py View on Github external
username = db.Column(db.String(50), unique=True)
    slug = db.Column(db.String(100), unique=True)
    ignore = db.Column(db.Boolean, default=False)

    def __repr__(self):
        return '' % self.name

class Repository(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    gh_id = db.Column(db.Integer)
    name = db.Column(db.String(100))
    forks = db.Column(db.Integer)
    watchers = db.Column(db.Integer)
    size = db.Column(db.Integer)
    open_issues = db.Column(db.Integer)
    description = db.Column(db.Text)
    organization_id = db.Column(db.Integer, db.ForeignKey('organization.id'))
    organization = db.relationship('Organization',
        backref=db.backref('repositories', lazy='dynamic'))
    users = db.relationship("User", secondary="commit", backref="repositories")
    slug = db.Column(db.String(100), unique=True)
    last_commit_date = db.Column(db.DateTime)

    @hybrid_property
    def last_commit(self):
        return self.commits.order_by(desc(Commit.date)).first()

    def __repr__(self):
        return '' % self.name

class Commit(db.Model):
    id = db.Column(db.Integer, primary_key=True)
github dlapiduz / govcode.org / gh_import.py View on Github external
def get_or_create_user(self, user):
        u = User.query.filter_by(gh_id=user.id).first()
        if u is None:
            u = User()
            u.gh_id = user.id
            u.login = user.login
            u.avatar_url = user.avatar_url
            db.session.add(u)
            db.session.commit()
        return u
github pycook / cmdb / lib / ci.py View on Github external
attr_names.append(CIAttributeCache.get(attr.attr_id).attr_name)
            attr_names = set(attr_names)
            for attr_name in attr_names:
                Table = TableMap(attr_name=attr_name).table
                db.session.query(Table).filter(Table.ci_id == ci_id).delete()
            db.session.query(CIRelation).filter(
                CIRelation.first_ci_id == ci_id).delete()
            db.session.query(CIRelation).filter(
                CIRelation.second_ci_id == ci_id).delete()
            # db.session.query(CIAttributeHistory).filter(
            #     CIAttributeHistory.ci_id == ci_id).delete()

            db.session.flush()
            db.session.delete(ci)
            try:
                db.session.commit()
            except Exception as e:
                db.session.rollback()
                current_app.logger.error("delete CI error, {0}".format(str(e)))
                return abort(400, "delete CI error, {0}".format(str(e)))
            # todo: write history
            ci_delete.apply_async([ci.ci_id], queue="cmdb_async")
            return ci_id
        return abort(404, "CI {0} not found".format(ci_id))