Skip to content

Commit

Permalink
read config
Browse files Browse the repository at this point in the history
  • Loading branch information
pbcquoc committed Dec 9, 2020
1 parent 5e3fb5c commit 9baddaa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
20 changes: 10 additions & 10 deletions vietocr/tool/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
from vietocr.tool.utils import download_config

url_config = {
'vgg_transformer':'1TF8effeufpgkHqQFlmNWKsQtCMfDiooa',
'resnet_transformer':'1GGhQqtMz4WloBh38U4sMlzLN6cpw5iag',
'resnet_fpn_transformer':'1I3-m8wfVpsro1c3UupwxW97MYmP5evvh',
'vgg_seq2seq':'1lWUvdYnyZ6HI52I6THS_Zr97YwEzcROn',
'vgg_convseq2seq':'1f5On-N-Dc25LZq0ZHLR3uhNlHVPkXl60',
'vgg_decoderseq2seq':'10YrSoK_gFuuhTN_u6emOgYEu5v7Y4ksG',
'base':'1xiw7ZnT3WH_9HXoGpLbhW-m2Sm2nlthi',
'vgg_transformer':'vgg-transformer.yml',
'resnet_transformer':'resnet_transformer.yml',
'resnet_fpn_transformer':'resnet_fpn_transformer.yml',
'vgg_seq2seq':'vgg_seq2seq.yml',
'vgg_convseq2seq':'vgg_convseq2seq.yml',
'vgg_decoderseq2seq':'vgg_decoderseq2seq.yml',
'base':'base.yml',
}

class Cfg(dict):
Expand All @@ -18,13 +18,13 @@ def __init__(self, config_dict):

@staticmethod
def load_config_from_file(fname):
# base_config = download_config(url_config['base'])
base_config = download_config(url_config['base'])

with open(fname, encoding='utf-8') as f:
config = yaml.safe_load(f)
# base_config.update(config)
base_config.update(config)

return Cfg(config)
return Cfg(base_config)

@staticmethod
def load_config_from_name(name):
Expand Down
12 changes: 4 additions & 8 deletions vietocr/tool/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import yaml
import numpy as np
import uuid

import requests

def download_weights(id_or_url, cached=None, md5=None, quiet=False):
if id_or_url.startswith('http'):
Expand All @@ -15,13 +15,9 @@ def download_weights(id_or_url, cached=None, md5=None, quiet=False):


def download_config(id):
url = 'https://drive.google.com/uc?id={}'.format(id)
output = str(uuid.uuid4())
output = gdown.download(url, output=output, quiet=True)

with open(output, encoding='utf-8') as f:
config = yaml.safe_load(f)
os.remove(output)
url = 'https://raw.githubusercontent.com/pbcquoc/vietocr/master/config/{}'.format(id)
r = requests.get(url)
config = yaml.sale_load(r.text)

return config

Expand Down

0 comments on commit 9baddaa

Please sign in to comment.