File size: 1,794 Bytes
1f77b91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78

import os
import boto3
from io import BytesIO , StringIO
import pickle as pkl
from utils import *

def get_data_s3(filename):
    
    ACCESS_KEY = "AKIAUKUH7S3OIVOEIRWY"
    SECRET_KEY = "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"
    bucket = "root-models"

    s3 = boto3.client( "s3" , aws_access_key_id=ACCESS_KEY , aws_secret_access_key=SECRET_KEY )
    
    response = s3.get_object(Bucket=bucket, Key=filename)
    
    data = BytesIO( response["Body"].read() )

    return data


def parse_cfg_url(filename='yolov3.cfg'):

    data = get_data_s3(filename)

    lines = data.getvalue().decode().rstrip().lstrip().split('\n')     #store the lines in a list
    lines = [x.rstrip().lstrip() for x in lines]

    lines = [x for x in lines if len(x) > 0] #get read of the empty lines 
    lines = [x for x in lines if x[0] != '#']  
    lines = [x.rstrip().lstrip() for x in lines]

    
    block = {}
    blocks = []
    
    for line in lines:
        # print('line:' , line)
        if line[0] == "[":               #This marks the start of a new block
            if len(block) != 0:
                blocks.append(block)
                block = {}
            block["type"] = line[1:-1].rstrip()
        else:
            key,value = line.split("=")
            block[key.rstrip()] = value.lstrip()
    blocks.append(block)

    # print('blocks : 2 ' , blocks )

    return blocks

if __name__ == '__main__':
    # parse_cfg('yolov3.cfg')

    # parse_cfg_url('yolov3.cfg')

    # colors = pkl.load( open( "pallete", "rb") )

    # print(colors)

    # print()

    # colors = pkl.load( get_data_s3( "pallete" ) )

    # print(colors)

    classes = load_classes('data/coco.names')

    print( classes )

    print()

    classes = load_classes_url('coco.names')

    print( classes )