この様なエラーが出てしまいます。
どのようにすればよろしいのでしょうか
よろしくお願いします
tensorflow 1.4.0
jypiter notebook
---エラー文---
TypeError Traceback (most recent call last)
<ipython-input-150-03b95042d7b5> in <module>()
1 for i in range(100):
----> 2 batch_xs = X_train(10)
3 batch_ys = y_train(10)
TypeError: 'numpy.ndarray' object is not callable
データ数は
X_train 225
X_test 75
y_train 225
y_test 75
で
X_train[0]の値が
array([[[ 145., 118., 65.], [ 125., 97., 49.], [ 139., 117., 78.], ..., [ 75., 59., 46.], [ 87., 75., 53.], [ 57., 50., 32.]], [[ 118., 90., 50.], [ 102., 83., 53.], [ 131., 116., 83.], ..., [ 92., 75., 59.], [ 82., 67., 46.], [ 60., 51., 36.]], [[ 87., 67., 40.], [ 158., 128., 78.], [ 206., 183., 141.], ..., [ 67., 55., 39.], [ 61., 54., 36.], [ 60., 46., 33.]], ..., [[ 74., 53., 50.], [ 81., 60., 55.], [ 82., 57., 50.], ..., [ 38., 27., 21.], [ 41., 40., 22.], [ 56., 59., 38.]], [[ 70., 50., 43.], [ 56., 35., 30.], [ 81., 62., 55.], ..., [ 41., 35., 13.], [ 33., 26., 0.], [ 48., 34., 33.]], [[ 49., 37., 39.], [ 42., 28., 19.], [ 69., 48., 43.], ..., [ 26., 13., 5.], [ 26., 15., 9.], [ 50., 32., 20.]]], dtype=float32)
python
1from PIL import Image 2import os, glob 3import numpy as np 4import tensorflow as tf 5#from sklearn import cross_validation 6from sklearn import model_selection 7import matplotlib.pyplot as plt 8#import cv2 9 10X_train, X_test, y_train, y_test = np.load("./animal.npy") 11#Xが画像データ 12#yがラベルデータ 13 14#xy = X_train, X_test, y_train, y_test 15 16X_train = np.asarray(X_train) 17X_test = np.asarray(X_test) 18y_train = np.asarray(y_train) 19y_test = np.asarray(y_test) 20 21x = tf.placeholder(tf.float32,[None,784]) 22 23W=tf.Variable(tf.zeros([784,3])) 24b=tf.Variable(tf.zeros([3])) 25 26y=tf.nn.softmax(tf.matmul(x,W)+b ) 27 28y_=tf.placeholder(tf.float32,[None,3]) 29cross_entropy=tf.reduce_mean(-tf.reduce_sum(y_*tf.log(y),reduction_indices=[1])) 30 31train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy) 32 33init = tf.initialize_all_variables() 34**ボールドテキスト** 35sess=tf.Session() 36sess.run(init) 37 38X_train = X_train.astype(np.float32) #float32に変換 39X_test = X_test.astype(np.float32) 40y_train = y_train.astype(np.float32) 41y_train = y_train.astype(np.float32) 42 43for i in range(100): 44 batch_xs = X_train.next_batch(10) 45 batch_ys = y_train.next_batch(10) 46 sess.run(train_step, feed_dict={x: X_train[i], y_: y_train[i]}) 47 48correct_prediction = tf.equal(tf.argmax(y,1), tf.argmax(y_,1)) 49accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32)) 50sess.run(accuracy, feed_dict={x: mnist.test.images, y_: mnist.test.labels})
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/01/19 13:53