model_reader.py 697 字节
Newer Older
xiebaiyuan's avatar
xiebaiyuan 已提交
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
import os

import framework_pb2 as framework_pb2


def read_model(model_path):
    print('read_model.')
    path_8 = unicode(model_path, 'utf8')

    try:
        with open(path_8, "rb") as f_model:
            print get_file_size(model_path)
            desc = framework_pb2.ProgramDesc()
            desc.ParseFromString(f_model.read())
            print desc
            # print desc.blocks

    except IOError:
        print ": File not found.  Creating a new file."


def get_file_size(file_path):
    file_path = unicode(file_path, 'utf8')
    fsize = os.path.getsize(file_path)
    fsize = fsize / float(1024 * 1024)
    return round(fsize, 2)


xiebaiyuan's avatar
xiebaiyuan 已提交
29
path = "newyolo/__model__"
xiebaiyuan's avatar
xiebaiyuan 已提交
30
read_model(path)