如何使用open加载tensorflow模型

2024-04-20 09:16:10 发布

您现在位置:Python中文网/ 问答频道 /正文

进口cv2 导入tensorflow作为tf #我不想 #下载什么型号。 型号名称='情感' 模型\文件=模型\名称+'冻结\推断_图形.pb' 下载\u BASE='http://download.tensorflow.org/models/object_detection/'

# Path to frozen detection graph. This is the actual model that is used for the object detection.
# PATH_TO_CKPT = MODEL_NAME + '/frozen_inference_graph.pb'
PATH_TO_CKPT = 'age/frozen_inference_graph.pb'


# List of the strings that is used to add correct label for each box.
PATH_TO_LABELS1 = os.path.join('data', 'gender.pbtxt')
PATH_TO_LABELS2 = os.path.join('data', 'age.pbtxt')

NUM_CLASSES1 = 2
NUM_CLASSES2 = 7


# ## Download Model

# if not os.path.exists(MODEL_NAME + '/frozen_inference_graph.pb'):
if not os.path.exists('screwdriver_graph/frozen_inference_graph.pb'):
    print('Downloading the model')
    opener = urllib.request.URLopener()
    opener.retrieve(DOWNLOAD_BASE + MODEL_FILE, MODEL_FILE)
    tar_file = tarfile.open(MODEL_FILE)
    for file in tar_file.getmembers():
        file_name = os.path.basename(file.name)
        if 'frozen_inference_graph.pb' in file_name:
            tar_file.extract(file, os.getcwd())
    print('Download complete')

cv2.error:OpenCV(4.1.1)/io/OpenCV/modules/dnn/src/caffe/caffe_io.cpp:1121:错误:(-2:未指定的错误)失败:fs.U是否打开(). “无法打开”图形.pbtxt“在函数‘ReadProtoFromTextFile’中”


Tags: thetopathformodelisosfile