简体   繁体   English

非法指令:运行任何Tensorflow程序时出现4错误

[英]Illegal Instruction: 4 error when running any Tensorflow program

I am trying to train a Tensorflow Convolutional Neural Network, and I am always getting a cryptic error regardless of the environment in which i run the program. 我正在尝试训练Tensorflow卷积神经网络,无论运行程序的环境如何,我总是会收到一个隐秘的错误。

In Jupyter Notebook, the kernel simply dies. 在Jupyter Notebook中,内核只是死掉了。

In Terminal, I get "Illegal Instruction: 4" with no Traceback. 在终端中,我得到了“非法指令:4”,没有回溯。

In Pycharm, I get: "Process finished with exit code 132 (interrupted by signal 4: SIGILL)". 在Pycharm中,我得到:“进程完成,退出代码132(被信号4:SIGILL中断)”。

I have looked all over the Internet and I have not found any instance in which this particular error was thrown in this situation. 我在Internet上四处查看,但没有发现任何在这种情况下引发此特定错误的实例。 I would appreciate it if someone could help shed some light on this error. 如果有人可以帮助您阐明此错误,我将不胜感激。

I am using Mac OS X High Sierra with python 3.6.2 我正在将Mac OS X High Sierra与python 3.6.2结合使用

My code can be found below and, as I said earlier, there is no traceback. 我的代码可以在下面找到,正如我之前所说,没有回溯。

import tensorflow as tf
import numpy as np
import pandas as pd

# OS to load files and save checkpoints
import os

image_height = 60
image_width = 1

image1_height = 15
image2_width = 1
model_name = "tensorflowCNN"

train_data = np.asarray(pd.read_csv("/home/student/Desktop/TrainingInput.csv", usecols=[1]))
lis = train_data.tolist()
lis = lis[0:60]
lis = [x[0].strip('[]\n,') for x in lis]
nlis = []
for i in lis:
    nlis.append(i.split())
for i in range(len(nlis)):
    nlis[i] = [float(x) for x in nlis[i] if x != "...,"]
nlis = [np.mean(x) for x in nlis]

train_data = np.asarray(nlis)
train_labels = np.asarray(pd.read_csv("/home/student/Desktop/TrainingInput.csv", usecols=[2]))
mylist = train_labels.tolist()
mylist = mylist[0:60]
mylist = [x[0] for x in mylist]
for i in range(len(mylist)):
    if mylist[i] == "GravelTraining":
        mylist[i] = 1.0
    elif mylist[i] == "WaterTraining":
        mylist[i] = 2.0
    else:
        mylist[i] = 3.0
print(mylist)
train_labels = np.asarray(mylist)

eval_data = np.asarray(pd.read_csv("/home/student/Desktop/TestingInput.csv", usecols=[1]))
List = eval_data.tolist()
List = List[0:15]
eval_data = np.asarray(List)
eval_labels = np.asarray(pd.read_csv("/home/student/Desktop/TestingInput.csv", usecols=[2]))
myList = eval_labels.tolist()
myList = myList[0:15]
eval_labels = np.asarray(myList)

category_names = list(map(str, range(3)))

# TODO: Process mnist data
train_data = np.reshape(train_data, (-1, image_height, image_width, 1))
train_labels = np.reshape(train_labels, (-1, image_height, image_width, 1))
eval_labels = np.reshape(eval_labels, (-1, image1_height, image2_width, 1))
eval_data = np.reshape(eval_data, (-1, image1_height, image2_width, 1))


# TODO: The neural network
class ConvNet:

    def __init__(self, image_height, Image_width, num_classes, chan):
        self.input_layer = tf.placeholder(dtype=tf.float32, shape=[1, image_height, Image_width, chan], name="inputs")

        conv_layer_1 = tf.layers.conv2d(self.input_layer, filters=32, kernel_size=[5, 5], padding="same",
                                        activation=tf.nn.relu)
        pooling_layer_1 = tf.layers.max_pooling2d(conv_layer_1, pool_size=[2, 1], strides=1)

        conv_layer_2 = tf.layers.conv2d(pooling_layer_1, filters=64, kernel_size=[5, 5], padding="same",
                                        activation=tf.nn.relu)
        pooling_layer_2 = tf.layers.max_pooling2d(conv_layer_2, pool_size=[2,1], strides=2)

        conv_layer_3 = tf.layers.conv2d(pooling_layer_2, filters=128, kernel_size=[5,5], padding="same",
                                        activation=tf.nn.relu)
        pooling_layer_3 = tf.layers.max_pooling2d(conv_layer_3, pool_size=[2,1], strides=2)

        flattened_pooling = tf.layers.flatten(pooling_layer_1)
        dense_layer = tf.layers.dense(flattened_pooling, 60, activation=tf.nn.relu)

        dropout = tf.layers.dropout(dense_layer, rate=0.4, training=True)

        output_dense_layer = tf.layers.dense(dropout, num_classes)

        self.choice = tf.argmax(output_dense_layer, axis=1)
        self.probabilities = tf.nn.softmax(output_dense_layer)

        self.labels = tf.placeholder(dtype=tf.float32, name="labels")
        self.accuracy, self.accuracy_op = tf.metrics.accuracy(self.labels, self.choice)

        one_hot_labels = tf.one_hot(indices=tf.cast(self.labels, dtype=tf.int32), depth=num_classes)
        self.loss = tf.losses.softmax_cross_entropy(onehot_labels=one_hot_labels, logits=output_dense_layer)

        optimizer = tf.train.GradientDescentOptimizer(learning_rate=1e-2)
        self.train_operation = optimizer.minimize(loss=self.loss, global_step=tf.train.get_global_step())


# Training process:variables

training_steps = 20000
batch_size = 60

path = "./" + model_name + "-cnn/"

load_checkpoint = False

tf.reset_default_graph()
dataset = tf.data.Dataset.from_tensor_slices((train_data, train_labels))
dataset = dataset.shuffle(buffer_size=train_labels.shape[0])
dataset = dataset.batch(batch_size)
dataset = dataset.repeat()

dataset_iterator = dataset.make_initializable_iterator()
next_element = dataset_iterator.get_next()

cnn = ConvNet(image_height, image_width, 1, 1)
print("milestone1")
saver = tf.train.Saver(max_to_keep=2)
print('milestone2')
if not os.path.exists(path):
    os.makedirs(path)
print('milestone3')
with tf.Session() as sess:
    #     if load_checkpoint:
    #         print(path)
    #         checkpoint = tf.train.get_checkpoint_state(path)
    #         print(checkpoint)
    #         saver.restore(sess, checkpoint.model_checkpoint_path)
    #     else:
    sess.run(tf.global_variables_initializer())
    print('milestone4')
    sess.run(tf.local_variables_initializer())
    sess.run(dataset_iterator.initializer)
    for step in range(training_steps):
        current_batch = sess.run(next_element)
        batch_inputs = current_batch[0]
        batch_labels = current_batch[1]
        sess.run((cnn.train_operation, cnn.accuracy_op),
                 feed_dict={cnn.input_layer: batch_inputs, cnn.labels: batch_labels})

        if step % 1 == 0 and step > 0:
            current_acc = sess.run(cnn.accuracy)
            print("Accuracy at step " + str(step) + ":" + str(current_acc))
            saver.save(sess, path + model_name, step)

    print("Saving final checkpoint for training session.")
    saver.save(sess, path + model_name, step)

Thanks in advance. 提前致谢。

OK If you have the 2.66 GHz version that seems to me to be the the Arrendale architecture released 2010 in which case there is absolutely no chance it's going to work since that thing doesn't have AVX instructions as needed by the latest binaries of tensor flow. 好吧,如果您拥有的2.66 GHz版本在我看来是2010年发布的Arrendale架构,在这种情况下,绝对没有任何机会使用它,因为该组件没有最新的张量流所需的AVX指令。

Unless your CPU is Sandy Bridge or newer (so AVX instructions) 除非您的CPU是Sandy Bridge或更高版本(所以是AVX指令)

your options are: 您的选择是:

1) get a newer CPU 1)换一个新的CPU
2) install an older version of tensor flow 2)安装旧版本的张量流
3) compile tensor flow from source 3)从源头编译张量流

for downgrade version see. 有关降级版本,请参见。
Illegal instruction(core dumped) tensorflow 非法指令(核心转储)张量流
Illegal instruction when import tensorflow in Python 在Python中导入张量流时的非法指令

EDIT 编辑
It seems that although all Core (i3, i5, i7) and Xeon CPU Sandy Bridge and newer support AVX, this is not true of Celron, nor Pentium CPU's to this day, as of 2018. Check what the machine contains if buying hardware. 看起来,尽管所有Core(i3,i5,i7)和Xeon CPU Sandy Bridge及更新版本都支持AVX,但截至2018年,对于Celron或奔腾CPU而言,情况并非如此。如果购买硬件,请检查计算机中包含的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM