@dBegginer

Ошибка в tensorflow, которой нет или как это исправить?

import tensorflow as tf
import numpy as np

mnist = tf.keras.datasets.mnist

(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train, x_test = np.reshape(x_train/255.0, [-1, 28 * 28]) , np.reshape(x_test/255.0, [-1, 28 * 28])
y_train = tf.keras.utils.to_categorical(y_train, 10)

def next_batch(x_train, y_train, batch_size):
    shuffled_index = np.random.randint(0, len(y_train), batch_size)
    x_batch, y_batch = x_train[shuffled_index], y_train[shuffled_index]
    return x_batch, y_batch

tensor = tf.placeholder(tf.float32, [None, 28 * 28], name = "X")
target = tf.placeholder(tf.int32, [None, 10], name = "y")

W = tf.Variable(tf.random_normal(shape = (28 * 28, 10), dtype= tf.float32))
b = tf.Variable(tf.random_normal(shape = (10,), dtype= tf.float32))

output = tf.add(tf.matmul(tensor, W), b)

loss = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits_v2(logits= output, labels= target))

optimizer  = tf.train.AdamOptimizer(learning_rate = 0.01)
train_op = optimizer.minimize(loss)

init = tf.global_variables_initializer()

epoches = 10000

with tf.Session() as sess:
    init.run()

    for i in range(epoches):
        loss = 0
        x_batch, y_batch = next_batch(x_train, y_train, 24)

        _, loss = sess.run([train_op, loss], feed_dict= {tensor: x_batch, target: y_batch})
        if (i%1000 + 1) == 0:
            print(loss)


TypeError: Fetch argument 0 has invalid type , must be a string or Tensor. (Can not convert a int into a Tensor or Operation.)
  • Вопрос задан
  • 198 просмотров
Решения вопроса 1
@ivodopyanov
NLP, python, numpy, tensorflow
Две переменные с одинаковым названием
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы