def get(self, path, **params): """ GET an API path and return result. If ``_cached=True`` is provided, the cached session is used. """ params = params.copy() cached = params.pop('_cached', False) url = self.url(path) self.log.debug("GET from %r", url) response = (self.cached_session if cached else self.session).get( url, params=params) response.raise_for_status() result = AttrDict(response.json()) result._info.server = response.headers.get('Server', '') result._info.sen = response.headers.get('X-ASEN', '') return result
def update_page(self, page, body, minor_edit=True): """ Update an existing page. The page **MUST** have been retrieved using ``expand='body.storage,version,ancestors'``. """ if page.body.storage.value == body: self.log.debug("Update: Unchanged page '%s', doing nothing", page.title) else: data = { "id": page.id, "type": page.type, "title": page.title, "space": { "key": page._expandable.space.split('/')[-1], }, "body": { "storage": { "value": body, "representation": "storage", } }, "version": { "number": page.version.number + 1, "minorEdit": minor_edit }, "ancestors": [{ 'type': page.ancestors[-1].type, 'id': page.ancestors[-1].id }], } url = self.url('/content/{}'.format(page.id)) self.log.debug("PUT (update page) to %r", url) #import pprint; print('\nPAGE UPDATE'); pprint.pprint(data); print('') response = self.session.put(url, json=data) response.raise_for_status() page = AttrDict(response.json()) self.log.debug("Create '%s': %r", page.title, response) return page
def add_page(self, space_key, title, body, parent_id=None, labels=None): """ Create a new page. The body must be in 'storage' representation. """ data = { "type": "page", "title": title, "space": { "key": space_key, }, "body": { "storage": { "value": body, "representation": "storage", } } } if parent_id: data.update(dict(ancestors=[dict(type='page', id=parent_id)])) url = self.url('/content') self.log.debug("POST (add page) to %r", url) response = self.session.post(url, json=data) response.raise_for_status() page = AttrDict(response.json()) self.log.debug("Create '%s': %r", title, response) # Add any provided labels if labels: data = [dict(prefix='global', name=label) for label in labels] response = self.session.post(page._links.self + '/label', json=data) response.raise_for_status() self.log.debug("Labels for #'%s': %r %r", page.id, response, [i['name'] for i in response.json()['results']]) return page
self.name = f'DetModel_{backbone_type}_{neck_type}_{head_type}' def forward(self, x): x = self.backbone(x) x = self.neck(x) x = self.head(x) return x if __name__ == '__main__': import torch # db_config = AttrDict( # in_channels=3, # backbone=AttrDict(type='MobileNetV3', layers=50, model_name='large',pretrained=True), # neck=AttrDict(type='FPN', out_channels=256), # head=AttrDict(type='DBHead') # ) # x = torch.zeros(1, 3, 640, 640) # model = DetModel(db_config) db_config = AttrDict(in_channels=3, backbone=AttrDict(type='ResNet', layers=50, pretrained=True), neck=AttrDict(type='pse_fpn', out_channels=256), head=AttrDict(type='PseHead', H=640, W=640, scale=1)) x = torch.zeros(1, 3, 640, 640) model = DetModel(db_config)
head_type = config.head.pop('type') assert head_type in head_dict, f'head.type must in {head_dict}' self.head = head_dict[head_type](self.neck.out_channels, **config.head) self.name = f'DetModel_{backbone_type}_{neck_type}_{head_type}' def load_3rd_state_dict(self, _3rd_name, _state): self.backbone.load_3rd_state_dict(_3rd_name, _state) self.neck.load_3rd_state_dict(_3rd_name, _state) self.head.load_3rd_state_dict(_3rd_name, _state) def forward(self, x): x = self.backbone(x) x = self.neck(x) x = self.head(x) return x if __name__ == '__main__': import torch db_config = AttrDict( in_channels=3, backbone=AttrDict(type='MobileNetV3', layers=50, model_name='large',pretrained=True), neck=AttrDict(type='FPN', out_channels=256), head=AttrDict(type='DBHead') ) x = torch.zeros(1, 3, 640, 640) model = DetModel(db_config)
assert head_type in head_dict, f'head.type must in {head_dict}' self.head = head_dict[head_type](self.neck.out_channels, **config.head) self.name = f'DetModel_{backbone_type}_{neck_type}_{head_type}' def load_3rd_state_dict(self, _3rd_name, _state): self.backbone.load_3rd_state_dict(_3rd_name, _state) self.neck.load_3rd_state_dict(_3rd_name, _state) self.head.load_3rd_state_dict(_3rd_name, _state) def forward(self, x): x = self.backbone(x) x = self.neck(x) x = self.head(x) return x if __name__ == '__main__': import torch db_config = AttrDict( in_channels=3, backbone=AttrDict(type='ResNet', layers=18, pretrained=True), neck=AttrDict(type='DB_fpn', out_channels=256), head=AttrDict(type='DBHead') ) x = torch.zeros(1, 3, 640, 640) model = DetModel(db_config) out = model(x) print('Finished.')
self.name = f'DetModel_{backbone_type}_{neck_type}_{head_type}' def load_3rd_state_dict(self, _3rd_name, _state): self.backbone.load_3rd_state_dict(_3rd_name, _state) self.neck.load_3rd_state_dict(_3rd_name, _state) self.head.load_3rd_state_dict(_3rd_name, _state) def forward(self, x): x = self.backbone(x) x = self.neck(x) x = self.head(x) return x if __name__ == '__main__': # from torchocr.model_config import AttrDict import torch db_config = AttrDict(in_channels=3, backbone=AttrDict(type='MobileNetV3', scale=0.5, model_name='large'), neck=AttrDict(type='FPN', out_channels=256), head=AttrDict(type='DBHead')) x = torch.zeros(1, 3, 640, 640) model = DetModel(db_config) y = model(x) print(model.name) print(y.shape)