Я попробовал модель Tensorflow, которая определяет k и x в уравнении прямой. Но я столкнулся с непонятной для меня проблемой. Я новичок в этом, поэтому я не могу объяснить вам мою проблему без тонны кода, извините. Ниже я оставлю свой код. Помоги мне, пожалуйста. Спасибо
import tensorflow as tf
import tensorflow.compat.v1 as tfc
graph = tf.Graph()
with graph.as_default():
with tf.name_scope('placeholders'):
x = tfc.placeholder(tf.float32, (3, 1))
y = tfc.placeholder(tf.float32, (3, ))
with tf.name_scope('weights'):
W = tf.Variable(tfc.random_normal((1, 1)))
b = tf.Variable(tfc.random_normal((1,)))
with tf.name_scope('prediction'):
y_pred = tf.matmul(x,W) + b
with tf.name_scope('loss'):
l = tf.reduce_sum((y-y_pred)**2)
#Добавить оптимизацию тренировки
with tf.name_scope('optim'):
#Задать скорость заучивания .001, как рекомендовано выше.
train_op = tfc.train.AdamOptimizer(.001).minimize(l)
with tf.name_scope('summaries'):
#Запись сводки о переменных(скалярных величинах) в заданный каталог журналов
tf.summary.scalar('loss', l)
#Объединение нескольких сводок в одну
merged = tfc.summary.merge_all()
train_writer = tfc.summary.FileWriter('/tmp/lr-train', graph)
n_steps = 1000
with tfc.Session() as sess:
sess.run(tfc.global_variables_initializer())
#Натренировать модель
for i in range(n_steps):
feed_dict = {x: [[1.], [2.], [3.]], y: [2., 3., 4.]}
_, summary, loss = sess.run([train_op, merged, l], feed_dict=feed_dict)
train_writer.add_summary(summary, i)
И у меня есть этот ответ
WARNING:tensorflow:From /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tensorflow_core/python/ops/resource_variable_ops.py:1635: calling BaseResourceVariable.__init__ (from tensorflow.python.ops.resource_variable_ops) with constraint is deprecated and will be removed in a future version.
Instructions for updating:
If using Keras pass *_constraint arguments to layers.
2020-01-09 22:31:46.911642: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2020-01-09 22:31:46.929626: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x7fca2060fab0 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-01-09 22:31:46.929649: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): Host, Default Version
Traceback (most recent call last):
File "/Users/ss/Desktop/mac/TensorFlow/Z1.py", line 34, in <module>
_, summary, loss = sess.run([train_op, merged, l], feed_dict=feed_dict)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tensorflow_core/python/client/session.py", line 960, in run
run_metadata_ptr)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tensorflow_core/python/client/session.py", line 1168, in _run
self._graph, fetches, feed_dict_tensor, feed_handles=feed_handles)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tensorflow_core/python/client/session.py", line 477, in __init__
self._fetch_mapper = _FetchMapper.for_fetch(fetches)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tensorflow_core/python/client/session.py", line 266, in for_fetch
return _ListFetchMapper(fetch)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tensorflow_core/python/client/session.py", line 378, in __init__
self._mappers = [_FetchMapper.for_fetch(fetch) for fetch in fetches]
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tensorflow_core/python/client/session.py", line 378, in <listcomp>
self._mappers = [_FetchMapper.for_fetch(fetch) for fetch in fetches]
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tensorflow_core/python/client/session.py", line 263, in for_fetch
(fetch, type(fetch)))
TypeError: Fetch argument None has invalid type <class 'NoneType'>