hahnyuan / darknet-visualizer

A visualizer of darknet nerual network's network
16 stars 5 forks source link

the last block is missing when parsing the cfg file #1

Closed xmfbit closed 5 years ago

xmfbit commented 5 years ago

A very useful tool, but there is a bug in read_cfg.py, where the last block is missing. An alternative is:

def read_cfg(filename):
    file=open(filename,'r')
    options=[]
    current={}
    for i in file.readlines():
        #print(i)
        if(i[0]=='['):
            options.append(current.copy())
            current.clear()
            current['type']=i.split(']')[0][1:]
            pass
        elif(i[0] in ['\0','#',';']):
            pass
        else:
            read_option(i,current)
    # the last block
    options.append(current)
    file.close()
    return options[1:]

Thanks for your sharing!