我已经使用python创建了一个带有tensorflow的程序,然后我使用pyinstaller构建了一个exe,首先我使用了这一行:
pyinstaller test.py
然后,因为它给了我模块tensorflow.python._pywrap_tensorflow_internal.pyd的导入错误 我将此文件复制到名为tensorflow \ python的dist \ test \目录的新文件夹中。然后我用这条线重复建筑物:
pyinstaller test.py -F --add-data "C:\path\dist\test\tensorflow\python\tensorflow.python._pywrap_tensorflow_internal.pyd";"C:\path\dist"
现在导入错误消失了,但是程序仍然崩溃并且我遇到了这个错误:
C:\ path \ dist \ tensorflow.python._pywrap_tensorflow_internal.pyd无法提取
打开:无效的参数
该问题的解决方案是什么?
我正在尝试构建的脚本是这样的:
import pyscreenshot as ImageGrab
from win32api import GetSystemMetrics
import os
import cv2
import numpy as np
import tensorflow as tf
import sys
import warnings
import h5py
import time
def Condition(data):
global name
for ch in data:
if ch['name'] != name:
print("data name:",ch['name'])
name = ch['name']
UpdateLabels(data, labels)
def GetName(data, name):
for ch in data:
name = ch['name']
return name
def UpdateLabels(data, labels):
for ch in data:
if ch['name'] == "ace":
labels["ace"] += 1
elif ch['name'] == "king":
labels["king"] += 1
elif ch['name'] == "queen":
labels["queen"] += 1
elif ch['name'] == "jack":
labels["jack"] += 1
elif ch['name'] == "ten":
labels["ten"] += 1
elif ch['name'] == "nine":
labels["nine"] += 1
elif ch['name'] == "eight":
labels["eight"] += 1
elif ch['name'] == "seven":
labels["seven"] += 1
elif ch['name'] == "six":
labels["six"] += 1
elif ch['name'] == "five":
labels["five"] += 1
elif ch['name'] == "four":
labels["four"] += 1
elif ch['name'] == "three":
labels["three"] += 1
elif ch['name'] == "two":
labels["two"] += 1
return labels
def UpdateCounter(data, c):
for ch in data:
if ch['name'] == "ace":
c = c - labels["ace"]
if ch['name'] == "king":
c = c - labels["king"]
if ch['name'] == "queen":
c = c - labels["queen"]
if ch['name'] == "jack":
c = c - labels["jack"]
if ch['name'] == "ten":
c = c - labels["ten"]
if ch['name'] == "six":
c = c + labels["six"]
if ch['name'] == "five":
c = c + labels["five"]
if ch['name'] == "four":
c = c + labels["four"]
if ch['name'] == "three":
c = c + labels["three"]
if ch['name'] == "two":
c = c + labels["two"]
return c
if __name__ == '__main__':
sys.path.append("..")
from utils import label_map_util
from utils import visualization_utils as vis_util
MODEL_NAME = 'inference_graph'
IMAGE_NAME = 'test1.jpg'
CWD_PATH = os.getcwd()
PATH_TO_CKPT = os.path.join(CWD_PATH,MODEL_NAME,'frozen_inference_graph.pb')
PATH_TO_LABELS = os.path.join(CWD_PATH,'training','labelmap.pbtxt')
PATH_TO_IMAGE = os.path.join(CWD_PATH,IMAGE_NAME)
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
NUM_CLASSES = 13
label_map = label_map_util.load_labelmap(PATH_TO_LABELS)
categories = label_map_util.convert_label_map_to_categories(label_map, max_num_classes=NUM_CLASSES, use_display_name=True)
category_index = label_map_util.create_category_index(categories)
detection_graph = tf.Graph()
with detection_graph.as_default():
od_graph_def = tf.GraphDef()
with tf.gfile.GFile(PATH_TO_CKPT, 'rb') as fid:
serialized_graph = fid.read()
od_graph_def.ParseFromString(serialized_graph)
tf.import_graph_def(od_graph_def, name='')
sess = tf.Session(graph=detection_graph)
image_tensor = detection_graph.get_tensor_by_name('image_tensor:0')
detection_scores = detection_graph.get_tensor_by_name('detection_scores:0')
detection_classes = detection_graph.get_tensor_by_name('detection_classes:0')
num_detections = detection_graph.get_tensor_by_name('num_detections:0')
c = 0
labels = {"ace" : 0, "king": 0, "queen": 0, "jack": 0, "ten": 0, "nine": 0, "eight": 0,"seven": 0, "six": 0, "five": 0, "four":0, "three": 0, "two": 0}
name = None
while True:
with warnings.catch_warnings():
warnings.filterwarnings("ignore",category=FutureWarning)
screenshot=ImageGrab.grab(bbox=(42,42, GetSystemMetrics(0),GetSystemMetrics(1)))
screenshot.save(IMAGE_NAME)
time.sleep(1)
image = cv2.imread(PATH_TO_IMAGE)
image_expanded = np.expand_dims(image, axis=0)
(scores, classes, num) = sess.run(
[detection_scores, detection_classes, num_detections],
feed_dict={image_tensor: image_expanded})
data = [category_index.get(value) for index,value in enumerate(classes[0]) if scores[0,index] > 0.98]
Condition(data)
print(UpdateCounter(data, c))