我应该如何处理错误“您的CPU支持这个TensorFlow二进制文件没有编译为使用的指令:SSE4.1 SSE4.2”

2024-04-18 10:46:11 发布

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

我正在写一个网络来识别带有Tensorlow(版本==1.5)的captcha,结果出错了。如果我安装2.0 Tensorflow,我会得到错误

Illegal instruction (core dumped)

我用python predict.py --image images/ж.png --model output/simple_nn.model --label-bin output/simple_nn_lb.pickle --flatten 1行运行脚本

from keras.models import load_model
import argparse
import keras
import pickle
import cv2

ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True,
    help="path to input image we are going to classify")
ap.add_argument("-m", "--model", required=True,
    help="path to trained Keras model")
ap.add_argument("-l", "--label-bin", required=True,
    help="path to label binarizer")
ap.add_argument("-w", "--width", type=int, default=32,
    help="target spatial dimension width")
ap.add_argument("-e", "--height", type=int, default=42,
    help="target spatial dimension height")
ap.add_argument("-f", "--flatten", type=int, default=-1,
    help="whether or not we should flatten the image")
args = vars(ap.parse_args())

image = cv2.imread(args["image"])
output = image.copy()
image = cv2.resize(image, (args["width"], args["height"]))

image = image.astype("float") / 255.0


if args["flatten"] > 0:
    image = image.flatten()
    image = image.reshape((1, image.shape[0]))

else:
    image = image.reshape((1, image.shape[0], image.shape[1],
        image.shape[2]))

print("[INFO] loading network and label binarizer...")
model = keras.models.load_model(args["model"])
lb = pickle.loads(open(args["label_bin"], "rb").read())

preds = model.predict(image)
print(preds)

i = preds.argmax(axis=1)[0]
label = lb.classes_[i]

text = "{}: {:.2f}%".format(label, preds[0][i] * 100)
cv2.putText(output, text, (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 0.7,
    (0, 0, 255), 2)
cv2.imshow("Image", output)
cv2.waitKey(0)

Tags: toimageimportaddoutputmodelhelpargs