Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
324 views
in Technique[技术] by (71.8m points)

python - 具有多个输入参数和多个输出参数的神经网络(Neural network with several input parameters and several output parameters)

I have started to deal with Tensorflow.

(我已经开始处理Tensorflow。)

In an exercise on Udacity I learned to create a neural network that can convert Celsius to Fahrenheit.

(在关于Udacity的练习中,我学会了创建一个神经网络,该网络可以将摄氏温度转换为华氏温度。)

For training the neural net was given 3 examples:

(为了训练神经网络,给出了3个示例:)

celsius_q = np.array([-40, -10, 0, 8, 15, 22, 38], dtype=float) fahrenheit_a = np.array([-40, 14, 32, 46, 59, 72, 100], dtype=float)

(celsius_q = np.array([-40,-10,0,8,15,22,38],dtype = float)fahrenheit_a = np.array([-40,14,32,46,59,72,100] ,dtype = float))

Now I would like to deal with a more complex problem.

(现在,我想处理一个更复杂的问题。)

I have a measurement series with 3 measurement series as examples.

(我有一个测量系列,以3个测量系列为例。)

For each measurement series I have 4 input parameters (Inputs) and 3 corresponding measured values (Outputs).

(对于每个测量系列,我都有4个输入参数(输入)和3个相应的测量值(输出)。)

excel_table I now want to create a neural network and give it the 3 measurement series to train.

(excel_table我现在想创建一个神经网络,并给它提供3个测量序列进行训练。)

Then I want to enter a set of input parameters and the neural network should give me the outputs.

(然后,我想输入一组输入参数,然后神经网络应该给我输出。)

I took the existing code from my exercise on Udacity and tried to convert it to my use case.

(我从有关Udacity的练习中获取了现有代码,并尝试将其转换为用例。)

Unfortunately, I have not yet achieved success.

(不幸的是,我尚未取得成功。)

The code is here:

(代码在这里:)

Import (进口)

import tensorflow as tf
import numpy as np

Set up training data (设置训练数据)

inputMatrix = np.array([(100,230,0.95,100),
                        (200,245,0.99,121),
                        ( 40,250,0.91,123)],dtype=float)
outputMatrix = np.array([(120, 5,120),
                         (123,24,100),
                         (154, 3,121)],dtype=float)
for i,c in enumerate(inputMatrix):
print("{}Input Matrix={}Output Matrix".format(c,outputMatrix[i]))

Create the Model (创建模型)

l0 = tf.keras.layers.Dense(units = 4, input_shape = [4])
l1 = tf.keras.layers.Dense(units = 64)
l2 = tf.keras.layers.Dense(units = 128)
l3 = tf.keras.layers.Dense(units = 3)

model = tf.keras.Sequential([l0,l1,l2,l3])

Compile the Model (编译模型)

model.compile(loss='mean_squared_error', optimizer=tf.keras.optimizers.Adam(0.1))

Train the model (训练模型)

history = model.fit(inputMatrix,outputMatrix,epochs=500,verbose=False)
print("Finished training the model!")

Display training statistics (显示培训统计数据)

import matplotlib.pyplot as plt
plt.xlabel('Epoch Number')
plt.ylabel('Loss Magnitude')
plt.plot(history.history['loss'])

Use the model to predict values (使用模型预测值)

print(model.predict([120,260,0.98,110]))`

I think a problem is that under "Set up training data" the 3 measurement series are not implemented correctly.

(我认为一个问题是,在“设置培训数据”下,这3个测量系列未正确实施。)

If I execute the code under "Train the Model", the training is finished very quickly, which should not be the case with such a complex task.

(如果我在“训练模型”下执行代码,则训练会非常迅速地完成,而对于如此复杂的任务则不应该如此。)

I hope someone can help me learn step by step and solve this problem.

(我希望有人可以帮助我逐步学习并解决此问题。)

  ask by masterkey translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...