错误“您的CPU支持该TensorFlow二进制文件未编译为使用的指令:SSE4.1 SSE4.2”,我该怎么办?

时间:2019-10-04 18:01:14

标签: python tensorflow

我正在编写一个网络来识别Tensorlow(版本== 1.5)的验证码,并得到了错误。如果我安装了2.0 Tensorflow,我会收到错误

  

非法指令(核心已转储)

我在行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)

1 个答案:

答案 0 :(得分:0)

如果CPU启用了AVX,AVX2和FMA,则应从为CPU优化的源中重新安装tensorflow二进制文件。请参阅下面的链接以获取更多信息:

https://github.com/tensorflow/tensorflow/issues/8037

相关问题