神经网络回归所需的输入形状不确定

时间:2018-12-27 09:32:12

标签: python python-3.x list tensorflow input

我正在尝试对某些航班数据进行回归分析。我加载了参数(先前的.mat文件),现在在格式列表中有6个参数作为预测变量,在格式列表中也有一个响应参数。

到目前为止,我所做的是将预测变量合并到一个合并列表中。现在我想创建一个模型并对其进行训练,但是正如我所期望的,格式列表并不兼容。我得到的错误是:AttributeError:'列表'对象没有属性'shape'

因此,我尝试使用tf.convert_to_tensor将列表转换为张量。不幸的是,它不起作用。我现在收到的错误是:ValueError:设置具有序列的数组元素

不幸的是,我只学习了如何使用Tensorflow中的CNN进行图像分类,但我不确定哪种格式适合将数据提供给输入层。现在,我的预测变量由每0.1秒获取的6个参数组成。列表的形状如下:

[[('__header__', b'MATLAB 5.0 MAT-file, Platform: PCWIN64, Created on: Wed Dec 26 19:17:10 2018'), ('__version__', '1.0'), ('__globals__', []), ('RSVRQuantity_Center', array([[111],
       [111],
       [111],
       ...,
       [104],
       [104],
       [104]], dtype=uint8))], [('__header__', b'MATLAB 5.0 MAT-file, Platform: PCWIN64, Created on: Wed Dec 26 19:32:29 2018'), ('__version__', '1.0'), ('__globals__', []), ('RSVRTemp_Center', array([[36.5  ],
       [36.5  ],
       [36.5  ],
       ...,
       [ 4.625],
       [ 4.625],
       [ 4.625]]))], [('__header__', b'MATLAB 5.0 MAT-file, Platform: PCWIN64, Created on: Wed Dec 26 19:33:00 2018'), ('__version__', '1.0'), ('__globals__', []), ('AirDrivenPumpTemp1_Center', array([[ 35.9 ],
       [ 35.9 ],
       [ 35.9 ],
       ...,
       [-13.75],
       [-13.75],
       [-13.75]]))], [('__header__', b'MATLAB 5.0 MAT-file, Platform: PCWIN64, Created on: Wed Dec 26 19:33:29 2018'), ('__version__', '1.0'), ('__globals__', []), ('AirDrivenPumpTemp2_Center', array([[ 35.9 ],
       [ 35.9 ],
       [ 35.9 ],
       ...,
       [-13.13],
       [-13.13],
       [-13.13]]))], [('__header__', b'MATLAB 5.0 MAT-file, Platform: PCWIN64, Created on: Wed Dec 26 19:34:12 2018'), ('__version__', '1.0'), ('__globals__', []), ('ElecPumpTemp1_Center', array([[45.9 ],
       [45.9 ],
       [45.9 ],
       ...,
       [14.63],
       [14.63],
       [14.63]]))], [('__header__', b'MATLAB 5.0 MAT-file, Platform: PCWIN64, Created on: Wed Dec 26 19:33:54 2018'), ('__version__', '1.0'), ('__globals__', []), ('ElecPumpTemp2_Center', array([[43.6 ],
       [43.6 ],
       [43.6 ],
       ...,
       [12.75],
       [12.75],
       [12.75]]))]]

到目前为止,我创建的模型如下:

def GradientDescent(features, labels, mode):

    # create an dense layer as input layer with 6 units for 6 features and ReLU activation function
    input_layer = tf.layers.dense(inputs=features["x"], units=6, activation=tf.nn.relu)

    # declare a dense layer with 12 units and ReLU activation function
    hidden1 = tf.layers.dense(inputs=input_layer, units=12, activation=tf.nn.relu)

    # declare a dense layer with 12 units and ReLU activation function
    hidden2 = tf.layers.dense(inputs=hidden1, units=12, activation=tf.nn.relu)

    # declare a dense layer with 6 units and ReLU activation function
    hidden3 = tf.layers.dense(inputs=hidden2, units=6, activation=tf.nn.relu)

    # declare a dense layer with 1 unit as output layer
    logits = tf.layers.dense(inputs=hidden3, units=1)

    predictions = tf.argmax(input=logits, axis=1)

    # return the estimator when predicting (no loss and training function needs to be defined here)
    if mode == tf.estimator.ModeKeys.PREDICT:
        return tf.estimator.EstimatorSpec(mode=mode, predictions=predictions)

    # declare the loss function sparse softmax cross entropy
    loss = tf.losses.sparse_softmax_cross_entropy(labels=labels,logits=logits)

    # declare a decreasing learning rate
    # starter_learning_rate = 0.1
    # global_step = tf.Variable(0, trainable=False)
    # learning_rate = tf.train.exponential_decay(starter_learning_rate, global_step, 10000, 0.96, staircase=True)

    # declare a gradient descent optimizer with a decreasing learning rate
    optimizer = tf.train.GradientDescentOptimizer(learning_rate=0.01)

    train_op = optimizer.minimize(loss=loss, global_step=tf.train.get_global_step())

    # define the accuracy error metric
    eval_metric_ops = {
        "accuracy": tf.metrics.accuracy(labels=labels, predictions=predictions)
    }

    #tf.summary.scalar('accuracy', accuracy)

    return tf.estimator.EstimatorSpec(mode=mode, loss=loss, train_op=train_op, predictions=predictions, eval_metric_ops=eval_metric_ops)

我正在提供数据来像这样进行训练:

HydSysPress_Center_PTRTRQ = tf.estimator.Estimator(model_fn=GradientDescent, model_dir="GradDescent_10000")

train_input = tf.estimator.inputs.numpy_input_fn(x={"x": Predictors}, y=HydSysPress_Center, batch_size=64, num_epochs=None, shuffle=False)
HydSysPress_Center_PTRTRQ.train(input_fn=train_input, steps=100)

我想开始训练模型时不要混淆参数的列和行,因为每个参数都带有固定的时间戳。对于每个有用的答案,我将非常感谢!

0 个答案:

没有答案