Python re.findall() Examples

The following are 30 code examples for showing how to use re.findall(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module re , or try the search function .

Example 1
Project: VEX_Syntax   Author: WhileRomeBurns   File: vcc_utils.py    License: MIT License 6 votes vote down vote up
def context_function_signatures(context, vcc_path=VCC_PATH):
    ctx_info = subprocess.check_output([vcc_path, '-X', context])
    ctx_info = ctx_info.decode('ascii')

    sigs = []
    for s in re.findall('(\w+(\[\])?) (\w+)\((.*)\)', ctx_info):
        sig_str  = '%s %s(%s)' % (s[0], s[2], s[3])
        if s[3] == 'void':
            hint_str = ''
        else:
            hint_str = '%s\n(%s)' % (s[0], s[3].rstrip().lstrip().rstrip(';'))
        args = [x.strip() for x in s[3].split(';')]
        sigs.append({'returns':s[0], 'name':s[2], 'ctx':context, 'args':args, 'str':sig_str,
                     'hint':hint_str})

    return sigs 
Example 2
def test_tutorial_tested():
    """
    Make sure that every tutorial that isn't in the whitelist
    has been added to the tutorial test file
    """
    tutorial_test_file = os.path.join(os.path.dirname(__file__), 'test_tutorials.py')
    f = open(tutorial_test_file, 'r')
    tutorial_test_text = '\n'.join(f.readlines())
    tutorial_path = os.path.join(os.path.dirname(__file__), '..', '..', 'docs', 'tutorials')
    tutorials = glob.glob(os.path.join(tutorial_path, '**', '*.md'))

    tested_tutorials = set(re.findall(r"assert _test_tutorial_nb\('(.*)'\)", tutorial_test_text))
    for tutorial in tutorials:
        friendly_name = '/'.join(tutorial.split('/')[-2:]).split('.')[0]
        if friendly_name not in tested_tutorials and friendly_name+".md" not in whitelist_set:
            assert False, "{} has not been added to the tests/tutorials/test_tutorials.py test_suite".format(friendly_name) 
Example 3
Project: DOTA_models   Author: ringringyi   File: utils.py    License: Apache License 2.0 6 votes vote down vote up
def parse_rec(filename):
    """ Parse a PASCAL VOC xml file """
    tree = ET.parse(filename)
    objects = []
    for obj in tree.findall('object'):
        obj_struct = {}
        obj_struct['name'] = obj.find('name').text
        obj_struct['pose'] = obj.find('pose').text
        obj_struct['truncated'] = int(obj.find('truncated').text)
        obj_struct['difficult'] = int(obj.find('difficult').text)
        bbox = obj.find('bndbox')
        obj_struct['bbox'] = [int(bbox.find('xmin').text),
                              int(bbox.find('ymin').text),
                              int(bbox.find('xmax').text),
                              int(bbox.find('ymax').text)]
        objects.append(obj_struct)
    return objects 
Example 4
Project: DOTA_models   Author: ringringyi   File: utils.py    License: Apache License 2.0 6 votes vote down vote up
def parse_labelme_poly(filename):
    """ Parse a labelme xml file """
    tree = ET.parse(filename)
    objects = []
    for obj in tree.findall('object'):
        obj_struct = {}
        obj_struct['name'] = obj.find('name').text
        obj_struct['deleted'] = obj.find('deleted').text
        obj_struct['verified'] = int(obj.find('verified').text)
        obj_struct['occluded'] = obj.find('occluded').text
        obj_struct['attributes'] = obj.find('attributes').text
        poly = obj.find('polygon').findall('pt')
        obj_struct['polygon'] = []
        for point in poly:
            pt = [point.find('x').text, point.find('y').text]
            obj_struct['polygon'] = obj_struct['polygon'] + pt
        objects.append(obj_struct)
    return objects 
Example 5
Project: DOTA_models   Author: ringringyi   File: utils.py    License: Apache License 2.0 6 votes vote down vote up
def reWriteImgWithMask(srcpath, dstpath, gtpath, srcform, dstform):
    namelist = GetFileFromThisRootDir(gtpath)
    for fullname in namelist:
        objects = parse_bod_poly(fullname)
        mask_polys = []
        for obj in objects:
            clsname = obj['name']
            matches = re.findall('area|mask', clsname)
            if 'mask' in matches:
                #print('mask:')
                mask_polys.append(shgeo.Polygon(obj['poly']))
            elif 'area' in matches:
                #print('area:')
                mask_polys.append(shgeo.Polygon(obj['poly']))
        basename = mybasename(fullname)
        imgname = os.path.join(srcpath, basename + srcform)
        img = cv2.imread(imgname)
        dstname = os.path.join(dstpath, basename + dstform)
        if len(mask_polys) > 0:
            saveimageWithMask(img, dstname, mask_polys) 
Example 6
Project: PickTrue   Author: winkidney   File: huaban.py    License: MIT License 6 votes vote down vote up
def __init__(self, board_url_or_id):
        board_id = str(board_url_or_id)
        self.fetcher = HuaBanFetcher()
        if "http" in board_id:
            board_id = re.findall(r'boards/(\d+)/', board_id)[0]
        self.id = board_id
        path = "/boards/{board_id}/".format(
            board_id=board_id,
        )
        self.base_url = urljoin(BASE_URL, path)
        self.further_pin_url_tpl = urljoin(
            self.base_url,
            "?{random_string}"
            "&max={pin_id}"
            "&limit=20"
            "&wfl=1"
        )

        # uninitialized properties
        self.pin_count = None
        self.title = None
        self.description = None
        self._pins = []
        self._init_board() 
Example 7
Project: PyOptiX   Author: ozen   File: compiler.py    License: MIT License 6 votes vote down vote up
def _has_modified_includes(cls, file_path, modified_after, depth=4):
        if depth == 0:
            return False

        include_pattern = '#include\s*"(.*)"'

        with open(file_path) as f:
            content = f.read()
            for included_path in re.findall(include_pattern, content):
                for compiler_include_path in cls._program_directories:
                    included_file_path = os.path.join(compiler_include_path, included_path)
                    if not os.path.exists(included_file_path):
                        continue

                    included_file_mtime = os.path.getmtime(included_file_path)

                    if included_file_mtime > modified_after:
                        return True
                    elif cls._has_modified_includes(included_file_path, modified_after, depth=depth - 1):
                        return True

        return False 
Example 8
Project: Dumb-Cogs   Author: irdumbs   File: adventure.py    License: MIT License 6 votes vote down vote up
def adventure_command(self, ctx, *, text):
        "Do something in your adventure"
        words = re.findall(r'\w+', text)
        if words:
            # await self.baudout(ctx, game.do_command(words))
            channel = ctx.message.channel
            server = ctx.message.server
            author = ctx.message.author
            try:
                team = self.players[server.id][channel.id][author.id]
            except:
                await self.bot.reply('You are not in an adventure. If your team has embarked on one, join them using `{}adventure join`, otherwise embark on your own adventure.'.format(ctx.prefix))
                return
            await self.baudout(ctx, self.game_loops[server.id][team][channel.id]["GAME"].do_command(words, ctx, self))

        pass


    # edited - irdumbs 
Example 9
Project: InsightAgent   Author: insightfinder   File: reportMetrics.py    License: Apache License 2.0 6 votes vote down vote up
def extract_fields_db2(obj, line, field_name_regex):
    line = '#'.join(re.split('\s*#', line))

    last_key = ''
    field_names = re.findall(field_name_regex, line)
    for field in reversed(field_names):
        split_at = line.find(field) + len(field)
        field_name = re.split('\s*:', field)[0]
        # don't overwrite existing fields
        if field_name in obj:
            continue
        else:
            obj[field_name] = ' '.join(line[split_at:].split())
            if not last_key:
                last_key = field_name
        line = line[:split_at - len(field)]
    return last_key 
Example 10
Project: py2swagger   Author: Arello-Mobile   File: method.py    License: MIT License 6 votes vote down vote up
def _get_path_parameters(self):
        """
        Creates parameters described in url path
        :return: list of parameters
        :rtype: list
        """
        params = []
        url_parameters = re.findall(r'/{(.+?)}', self.introspector.path)

        for parameter in url_parameters:
            params.append({
                'name': parameter,
                'type': 'string',
                'in': 'path',
                'required': True
            })

        return params 
Example 11
Project: simplesam   Author: mdshw5   File: simplesam.py    License: MIT License 6 votes vote down vote up
def parse_md(self):
        """ Return the ungapped reference sequence from the MD tag, if present.
        """
        try:
            return self._cache['parse_md']
        except KeyError:
            pass
        try:
            md = self['MD']
        except KeyError:
            raise KeyError('MD tag not found in SAM record.')
        ref_seq = list(self.gapped('seq'))
        md_match = re.findall(r"([0-9]+)\^?([A-Z]+)?", md)
        ref_seq_i = 0
        for i, b in md_match:
            ref_seq_i += int(i)
            for mismatch in b:
                try:
                    ref_seq[ref_seq_i] = mismatch
                except IndexError:
                    raise IndexError(locals())
                ref_seq_i += 1
        self._cache['parse_md'] = ref_seq
        return ref_seq 
Example 12
Project: zbxdb   Author: ikzelf   File: tnslsnr-ping.py    License: GNU General Public License v3.0 6 votes vote down vote up
def ParseNestedParen(string, level):
    """
    Generate strings contained in nested (), indexing i = level
    """

    if len(re.findall(r"\(", string)) == len(re.findall(r"\)", string)):
        LeftRightIndex = [x for x in zip(
            [Left.start()+1 for Left in re.finditer(r'\(', string)],
            reversed([Right.start() for Right in re.finditer(r'\)', string)]))]

    elif len(re.findall(r"\(", string)) > len(re.findall(r"\)", string)):
        return ParseNestedParen(string + ')', level)

    elif len(re.findall(r"\(", string)) < len(re.findall(r"\)", string)):
        return ParseNestedParen('(' + string, level)

    else:
        return 'fail'

    return [string[LeftRightIndex[level][0]:LeftRightIndex[level][1]]] 
Example 13
Project: tensortrade   Author: tensortrade-org   File: helpers.py    License: Apache License 2.0 6 votes vote down vote up
def scale_times_to_generate(times_to_generate: int, time_frame: str):

    if 'MIN' in time_frame.upper():
        times_to_generate *= int(re.findall(r'\d+', time_frame)[0])
    elif 'H' in time_frame.upper():
        times_to_generate *= int(re.findall(r'\d+', time_frame)[0]) * 60
    elif 'D' in time_frame.upper():
        times_to_generate *= int(re.findall(r'\d+', time_frame)[0]) * 60 * 24
    elif 'W' in time_frame.upper():
        times_to_generate *= int(re.findall(r'\d+', time_frame)[0]) * 60 * 24 * 7
    elif 'M' in time_frame.upper():
        times_to_generate *= int(re.findall(r'\d+', time_frame)[0]) * 60 * 24 * 7 * 30
    else:
        raise ValueError('Timeframe must be either in minutes (min), hours (H), days (D), weeks (W), or months (M)')

    return times_to_generate 
Example 14
Project: jawfish   Author: war-and-code   File: test_re.py    License: MIT License 6 votes vote down vote up
def test_string_boundaries(self):
        # See http://bugs.python.org/issue10713
        self.assertEqual(re.search(r"\b(abc)\b", "abc").group(1),
                         "abc")
        # There's a word boundary at the start of a string.
        self.assertTrue(re.match(r"\b", "abc"))
        # A non-empty string includes a non-boundary zero-length match.
        self.assertTrue(re.search(r"\B", "abc"))
        # There is no non-boundary match at the start of a string.
        self.assertFalse(re.match(r"\B", "abc"))
        # However, an empty string contains no word boundaries, and also no
        # non-boundaries.
        self.assertEqual(re.search(r"\B", ""), None)
        # This one is questionable and different from the perlre behaviour,
        # but describes current behavior.
        self.assertEqual(re.search(r"\b", ""), None)
        # A single word-character string has two boundaries, but no
        # non-boundary gaps.
        self.assertEqual(len(re.findall(r"\b", "a")), 2)
        self.assertEqual(len(re.findall(r"\B", "a")), 0)
        # If there are no words, there are no boundaries
        self.assertEqual(len(re.findall(r"\b", " ")), 0)
        self.assertEqual(len(re.findall(r"\b", "   ")), 0)
        # Can match around the whitespace.
        self.assertEqual(len(re.findall(r"\B", " ")), 2) 
Example 15
Project: BASS   Author: Cisco-Talos   File: avclass_common.py    License: GNU General Public License v2.0 5 votes vote down vote up
def __norm_cat(self, label, hashes):
        if not label:
            return []

        # Initialize list of tokens to return
        ret = []

        # Split label into tokens and process each token
        for token in re.split("[^0-9a-zA-Z]", label):
            # Remove leading and trailing backspace from token
            # and convert to lowercase
            token = token.lower()

            # Remove digits at the end
            # FIXME: What if it is a hash, and removes digits at the end???
            end_len = len(re.findall("\d*$", token)[0])
            if end_len:
                token = token[:-end_len]

            # Ignore short token
            if len(token) < 4:
                continue

            # Ignore token if prefix of a hash of the sample 
            # Most AVs use MD5 prefixes in labels, 
            # but we check SHA1 and SHA256 as well
            hash_token = False
            for hash_str in hashes:
                if hash_str[0:len(token)] == token:
                    hash_token = True
                    break
            if hash_token:
                continue
            for keys, values in self.cat.iteritems():
                if token in values:
                    token = keys
                    ret.append(token)
                    break
                    # Add token
        return ret 
Example 16
Project: VEX_Syntax   Author: WhileRomeBurns   File: compile_and_run.py    License: MIT License 5 votes vote down vote up
def version_tuple(name):
    """Given 'Houdini 13.0.376', returns the tuple (13, 0, 376)."""
    return tuple([int(d) for d in re.findall('[0-9]{1,4}', name)]) 
Example 17
Project: VEX_Syntax   Author: WhileRomeBurns   File: vcc_utils.py    License: MIT License 5 votes vote down vote up
def context_functions(context, vcc_path=VCC_PATH, as_set=False):
    """Return the sorted list of all function names for a vex context."""
    ctx_info = subprocess.check_output([vcc_path, '-X', context])
    ctx_info = ctx_info.decode('ascii')

    funcs = set()
    for f in re.findall('\w+\(', ctx_info):
        if len(f) > 1:
            funcs.add(f[:-1])

    if as_set:
        return funcs
    else:
        return sorted(list(funcs)) 
Example 18
Project: pkmeter   Author: pkkid   File: filters.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def to_int(value, default='na'):
    if value is None: return 0
    match = re.findall('^-*\d+', str(value))
    return int(match[0]) if match else default 
Example 19
Project: pkmeter   Author: pkkid   File: utils.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def value_type(value):
    return re.findall(r"(\w+?)\'", str(type(value)))[0].lower() 
Example 20
Project: pkmeter   Author: pkkid   File: template.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _parse(self):
        tmplstrs = re.findall(self.REGEX, self.tmplstr)
        for tmplstr in tmplstrs:
            varstr = tmplstr[len(self.TOKEN_START):-len(self.TOKEN_END)]
            variable = Variable(varstr)
            self.variables.append(variable)
            self.namespaces.add(variable.namespace) 
Example 21
Project: pkmeter   Author: pkkid   File: pkmixins.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _init_attributes(self):
        for attr, value in self.etree.attrib.items():
            callback = getattr(self, 'attribute_%s' % attr)
            assert callback, 'Unsupported attribute: %s' % attr
            if attr == 'iter':
                self.actions.append(Variable(value, callback))
            elif attr == 'showif':
                self.actions.append(TruthTemplate(value, callback))
            elif re.findall(Template.REGEX, value):
                self.actions.append(Template(value, callback))
            else:
                callback(value) 
Example 22
Project: pkmeter   Author: pkkid   File: externalip.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def update(self):
        response = utils.http_request(self.update_url).get('response')
        if response:
            content = response.read().decode('utf-8')
            matches = re.findall(REGEX_IP, content)
            self.data['ip'] = matches[0] if matches else ''
        super(Plugin, self).update() 
Example 23
Project: everyclass-server   Author: everyclass   File: views_api.py    License: Mozilla Public License 2.0 5 votes vote down vote up
def multi_people_schedule_search():
    keyword = request.args.get('keyword')
    if not keyword:
        return generate_error_response(None, api_helpers.STATUS_CODE_INVALID_REQUEST, 'missing keyword parameter')

    print([request.cookies.get('e_session')])

    search_result = entity_service.search(keyword)

    uid = get_logged_in_uid()

    print(f"session:{session.values()} \n uid:{uid}")

    items = []
    for s in search_result.students:
        eligible = False
        groups = re.findall(r'\d+', s.klass)
        if len(groups) > 0:
            if int(groups[0][:2]) + 5 >= datetime.date.today().year - 2000:
                eligible = True
        else:
            eligible = True

        if eligible:
            items.append(SearchResultItem(s.name, s.deputy + s.klass, "student", s.student_id_encoded,
                                          *user_service.has_access(s.student_id, uid, False)))

    items.extend([SearchResultItem(t.name, t.unit + t.title, "teacher", t.teacher_id_encoded,
                                   *user_service.has_access(t.teacher_id, uid, False)) for t in search_result.teachers])
    return generate_success_response({'items': items, 'keyword': keyword, 'is_guest': True if uid is None else False}) 
Example 24
Project: everyclass-server   Author: everyclass   File: klass_review.py    License: Mozilla Public License 2.0 5 votes vote down vote up
def new(cls, klass_id: int, user_id: str, rk: int, ra: int, fs: float, gr: int, comment: str):
        from everyclass.server.entity import service as entity_service
        student = entity_service.get_student(user_id)

        grade_str = ""
        groups = re.findall(r'\d+', student.klass)
        if len(groups) > 0:
            grade_str = f"{groups[0][:2]}级"

        db_session.add(KlassReview(klass_id=klass_id, user_identifier=user_id, user_nickname=f"{student.deputy}{grade_str}学生",
                                   rating_knowledge=rk, rating_attendance=ra, final_score=fs, gender_rate=gr, comments=comment))
        db_session.commit() 
Example 25
Project: gated-graph-transformer-network   Author: hexahedria   File: ggtnn_graph_parse.py    License: MIT License 5 votes vote down vote up
def tokenize(sent):
    '''Return the tokens of a sentence including punctuation.
    >>> tokenize('Bob dropped the apple. Where is the apple?')
    ['Bob', 'dropped', 'the', 'apple', '.', 'Where', 'is', 'the', 'apple', '?']
    '''
    return re.findall('(?:\w+)|\S',sent) 
Example 26
Project: CAMISIM   Author: CAMI-challenge   File: training_data.py    License: Apache License 2.0 5 votes vote down vote up
def loadDictFromAFile(filePath):
    """
        Returns a dictionary that is stored in a file.

        @param filePath: a file in which a dictionary is stored in format: (key tab item)

        @return: dict that represents mapping: (key -> list of items)
    """
    try:
        dictOfLists = dict([])
        f = open(os.path.normpath(filePath), 'r')

        for line in f:
            pair = re.findall('[^\t]+', common.noNewLine(line))
            assert len(pair) == 2, str('There are not two values separated by \t at line: ' + line)
            key = int(pair[0])
            val = int(pair[1])
            if key in dictOfLists:
                dictOfLists[key].append(val)
            else:
                list = []
                list.append(val)
                dictOfLists[key] = list

        return dictOfLists
    except Exception:
        print "Cannot create a file or write to it:", filePath
        raise
    finally:
        f.close() 
Example 27
Project: CAMISIM   Author: CAMI-challenge   File: taxonomy.py    License: Apache License 2.0 5 votes vote down vote up
def test1():

    config = Config(open(os.path.normpath('D:\\A_Phylo\\A_Metagenomic\\pPPS\\workspace\\pPPS\\config01.cfg')), 'pPPS')

    databaseFile = os.path.normpath(config.get('databaseFile'))
    taxonomicRanks = config.get('taxonomicRanks').split(',')
    t = Taxonomy(databaseFile, taxonomicRanks)

    s = 'Assignment of query to the lowest common ancestor of Bacteroides thetaiotaomicron (226186), Porphyromonas gingivalis (242619) and Parabacteroides distasonis (435591).'
    #s = 'Assignment of query to the lowest common ancestor of Bacteroides thetaiotaomicron , Porphyromonas gingivalis (242619) and Parabacteroides distasonis (435591).'
    #s = 'Assignment of query to the lowest common ancestor of Bacteroides thetaiotaomicron , Porphyromonas gingivalis  and Parabacteroides distasonis (435591).'
    #s = 'Assignment of query to the lowest common ancestor of Bacteroides thetaiotaomicron (226186) and Parabacteroides distasonis (435591).'
    #s = 'Assignment of query to the lowest common ancestor of Halobacterium sp. (64091), Thermococcus kodakarensis (69014), Pyrococcus horikoshii (70601), Methanothermobacter thermautotrophicus (187420), Methanopyrus kandleri AV19 (190192), Methanosarcina mazei (192952), Archaeoglobus fulgidus (224325), Methanocaldococcus jannaschii (243232), Methanococcoides burtonii (259564), Methanococcus maripaludis S2 (267377), Haloarcula marismortui (272569), Methanospirillum hungatei (323259), Methanosphaera stadtmanae (339860), Natronomonas pharaonis (348780), Methanosaeta thermophila PT (349307), Candidatus methanoarchaeon RC1 (351160), Haloquadratum walsbyi (362976), Methanoculleus marisnigri JR1 (368407), Methanocorpusculum labreanum (410358) and Methanobrevibacter smithii (420247).'
    #s = 'Assignment of query to the lowest common ancestor of Thermococcus kodakarensis (69014) and Pyrococcus horikoshii (70601).'
    list = re.findall(r'\([0-9]+\)', s)
    list2 = []
    for i in list:
        str = re.sub(r'\(([0-9]+)\)', r'\1', i)
        list2.append(str)
        print str
    print '-------------------------'


    pathDict = t.getPathFromLowestCommonAncestorToRoot(list2)
    #pathDict = t.getPathToRoot(170187)

    for k in taxonomicRanks:
        if k not in pathDict:
            break
        n = pathDict[k]
        print n.ncbid, n.rank, n.name 
Example 28
Project: invana-bot   Author: invanalabs   File: single.py    License: MIT License 5 votes vote down vote up
def get_method(self):
        def custom_float(data):
            data = re.findall(r"[-+]?\d*\.\d+|[-+]?\d+", data)
            if len(data) > 0:
                return float(data[0])
            else:
                return float(0)
        return custom_float 
Example 29
Project: dynamic-training-with-apache-mxnet-on-aws   Author: awslabs   File: main.py    License: Apache License 2.0 5 votes vote down vote up
def load_model(args, contexts, data_train):
    # load model from model_name prefix and epoch of model_num_epoch with gpu contexts of contexts
    mode = args.config.get('common', 'mode')
    load_optimizer_states = args.config.getboolean('load', 'load_optimizer_states')
    is_start_from_batch = args.config.getboolean('load', 'is_start_from_batch')

    from importlib import import_module
    symbol_template = import_module(args.config.get('arch', 'arch_file'))
    is_bucketing = args.config.getboolean('arch', 'is_bucketing')

    if mode == 'train':
        if is_bucketing:
            bucketing_arch = symbol_template.BucketingArch(args)
            model_loaded = bucketing_arch.get_sym_gen()
        else:
            model_loaded = symbol_template.arch(args)
        model_num_epoch = None
    elif mode == 'load' or mode == 'predict':
        model_file = args.config.get('common', 'model_file')
        model_name = os.path.splitext(model_file)[0]
        model_num_epoch = int(model_name[-4:])
        if is_bucketing:
            bucketing_arch = symbol_template.BucketingArch(args)
            model_loaded = bucketing_arch.get_sym_gen()
        else:
            model_path = 'checkpoints/' + str(model_name[:-5])

            data_names = [x[0] for x in data_train.provide_data]
            label_names = [x[0] for x in data_train.provide_label]

            model_loaded = mx.module.Module.load(
                prefix=model_path, epoch=model_num_epoch, context=contexts,
                data_names=data_names, label_names=label_names,
                load_optimizer_states=load_optimizer_states)
        if is_start_from_batch:
            import re
            model_num_epoch = int(re.findall('\d+', model_file)[0])

    return model_loaded, model_num_epoch 
Example 30
Project: dynamic-training-with-apache-mxnet-on-aws   Author: awslabs   File: benchmark.py    License: Apache License 2.0 5 votes vote down vote up
def images_processed(log_loc, mode):
    f = open(log_loc)
    if mode == 'native':
        img_per_sec = re.findall("(?:Batch\s+\[30\]\\\\tSpeed:\s+)(\d+\.\d+)(?:\s+)", str(f.readlines()))
    else:
        img_per_sec = re.findall("(?:Batch\s+\[3\]\\\\tSpeed:\s+)(\d+\.\d+)(?:\s+)", str(f.readlines()))
    f.close()
    img_per_sec = map(float, img_per_sec)
    total_img_per_sec = sum(img_per_sec)
    return total_img_per_sec