コードに理由が見つからないバグがあります。これが私のjupyterノートブックのコピーです:
# coding: utf-8
# In[1]:
import tensorflow as tf
import tflearn
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from sklearn.utils import shuffle
get_ipython().magic(u'matplotlib inline')
# # Data import and processing:
# In[13]:
# Import dataframe
path60 = './6060DataFrame.pkl'
df60 = pd.read_pickle(path60)
# Separate pandas dataframe into classification and data arrays
classData = df60["Classification"].as_matrix()
coilData = df60["Coil Data"].as_matrix()
# Cut coil data to every 40th point
coilDataCut = np.zeros((16000, 750), dtype="float32")
for j in np.arange(0,40,1):
for i in np.arange(0,400,1):
coilDataCut[i+j*400] = np.hstack(coilData[i])[j::40]
# Convert label data to one-hot array
classDataOH = np.zeros((400,2), dtype="float32")
classDataOH[np.arange(400), classData.astype(np.int)] = 1
classDataOH = classDataOH
classDataOH = np.tile(classDataOH, (40,1))
# Random shuffle
coilDataCut, classDataOH = shuffle(coilDataCut, classDataOH, random_state=0)
#classDataOH = np.reshape(classDataOH,[16000,2,1])
cDCut = np.reshape(coilDataCut,[16000,15,50,1])
# In[16]:
coillst = []
classlst = []
for i in np.arange(0,16000):
coillst.append(cDCut[i])
classlst.append(classDataOH[i])
# # CNN:
# In[17]:
tf.reset_default_graph()
# Placeholders for input and outputs
x_image = tf.placeholder(tf.float32, shape=[None, 15, 50, 1])
y_ = tf.placeholder(tf.float32, shape=[None, 2, 1])
# Input layer:
net = tflearn.layers.core.input_data(shape=[None, 15, 50, 1])
# First layer:
net = tflearn.layers.conv.conv_2d(x_image, 32, 2, activation="relu")
net = tflearn.layers.conv.max_pool_2d(net, 2)
# Fully connected layer:
net = tflearn.layers.core.fully_connected(net, 1024, activation="relu")
# Output layer:
net = tflearn.layers.core.fully_connected(net, 2, activation="softmax")
net = tflearn.regression(net, optimizer='adam', loss='categorical_crossentropy', learning_rate=0.001)
# In[19]:
model = tflearn.DNN(net)
model.fit(coillst, classlst, validation_set=0.1, batch_size=50)
そして、スローされたエラーは次のとおりです。
---------------------------------
Run id: BYPF4R
Log directory: /tmp/tflearn_logs/
---------------------------------
Training samples: 16000
Validation samples: 0
--
---------------------------------------------------------------------------
InvalidArgumentError Traceback (most recent call last)
/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py in _do_call(self, fn, *args)
971 try:
--> 972 return fn(*args)
973 except errors.OpError as e:
/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py in _run_fn(session, feed_dict, fetch_list, target_list, options, run_metadata)
953 feed_dict, fetch_list, target_list,
--> 954 status, run_metadata)
955
/usr/lib/python3.5/contextlib.py in __exit__(self, type, value, traceback)
65 try:
---> 66 next(self.gen)
67 except StopIteration:
/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/errors.py in raise_exception_on_not_ok_status()
462 compat.as_text(pywrap_tensorflow.TF_Message(status)),
--> 463 pywrap_tensorflow.TF_GetCode(status))
464 finally:
InvalidArgumentError: You must feed a value for placeholder tensor 'Placeholder' with dtype float
[[Node: Placeholder = Placeholder[dtype=DT_FLOAT, shape=[], _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
During handling of the above exception, another exception occurred:
InvalidArgumentError Traceback (most recent call last)
<ipython-input-19-321574ec4e87> in <module>()
2 model.fit(coillst, classlst, n_epoch=100, shuffle=True, # validation_set=(X_test, Y_test),
3 show_metric=True, batch_size=96,\
----> 4 snapshot_epoch=True)
5 #model.fit(coillst, classlst)#, validation_set=0.1, batch_size=50)
/usr/local/lib/python3.5/dist-packages/tflearn/models/dnn.py in fit(self, X_inputs, Y_targets, n_epoch, validation_set, show_metric, batch_size, shuffle, snapshot_epoch, snapshot_step, excl_trainops, run_id)
186 daug_dict=daug_dict,
187 excl_trainops=excl_trainops,
--> 188 run_id=run_id)
189
190 def predict(self, X):
/usr/local/lib/python3.5/dist-packages/tflearn/helpers/trainer.py in fit(self, feed_dicts, n_epoch, val_feed_dicts, show_metric, snapshot_step, snapshot_epoch, shuffle_all, dprep_dict, daug_dict, excl_trainops, run_id)
275 snapshot_epoch,
276 snapshot_step,
--> 277 show_metric)
278 global_loss += train_op.loss_value
279 if train_op.acc_value and global_acc:
/usr/local/lib/python3.5/dist-packages/tflearn/helpers/trainer.py in _train(self, training_step, snapshot_epoch, snapshot_step, show_metric)
682 tflearn.is_training(True, session=self.session)
683 _, train_summ_str = self.session.run([self.train, self.summ_op],
--> 684 feed_batch)
685
686 # Retrieve loss value from summary string
/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py in run(self, fetches, feed_dict, options, run_metadata)
715 try:
716 result = self._run(None, fetches, feed_dict, options_ptr,
--> 717 run_metadata_ptr)
718 if run_metadata:
719 proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)
/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py in _run(self, handle, fetches, feed_dict, options, run_metadata)
913 if final_fetches or final_targets:
914 results = self._do_run(handle, final_targets, final_fetches,
--> 915 feed_dict_string, options, run_metadata)
916 else:
917 results = []
/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py in _do_run(self, handle, target_list, fetch_list, feed_dict, options, run_metadata)
963 if handle is None:
964 return self._do_call(_run_fn, self._session, feed_dict, fetch_list,
--> 965 target_list, options, run_metadata)
966 else:
967 return self._do_call(_prun_fn, self._session, handle, feed_dict,
/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py in _do_call(self, fn, *args)
983 except KeyError:
984 pass
--> 985 raise type(e)(node_def, op, message)
986
987 def _extend_graph(self):
InvalidArgumentError: You must feed a value for placeholder tensor 'Placeholder' with dtype float
[[Node: Placeholder = Placeholder[dtype=DT_FLOAT, shape=[], _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
Caused by op 'Placeholder', defined at:
File "/usr/lib/python3.5/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/usr/lib/python3/dist-packages/ipykernel/__main__.py", line 3, in <module>
File "/usr/lib/python3/dist-packages/traitlets/config/application.py", line 658, in launch_instance
app.start()
File "/usr/lib/python3/dist-packages/ipykernel/kernelapp.py", line 474, in start
File "/usr/lib/python3/dist-packages/zmq/eventloop/ioloop.py", line 162, in start
super(ZMQIOLoop, self).start()
File "/usr/lib/python3/dist-packages/tornado/ioloop.py", line 887, in start
handler_func(fd_obj, events)
File "/usr/lib/python3/dist-packages/tornado/stack_context.py", line 275, in null_wrapper
return fn(*args, **kwargs)
File "/usr/lib/python3/dist-packages/zmq/eventloop/zmqstream.py", line 440, in _handle_events
self._handle_recv()
File "/usr/lib/python3/dist-packages/zmq/eventloop/zmqstream.py", line 472, in _handle_recv
self._run_callback(callback, msg)
File "/usr/lib/python3/dist-packages/zmq/eventloop/zmqstream.py", line 414, in _run_callback
callback(*args, **kwargs)
File "/usr/lib/python3/dist-packages/tornado/stack_context.py", line 275, in null_wrapper
return fn(*args, **kwargs)
File "/usr/lib/python3/dist-packages/ipykernel/kernelbase.py", line 276, in dispatcher
File "/usr/lib/python3/dist-packages/ipykernel/kernelbase.py", line 228, in dispatch_shell
File "/usr/lib/python3/dist-packages/ipykernel/kernelbase.py", line 390, in execute_request
File "/usr/lib/python3/dist-packages/ipykernel/ipkernel.py", line 196, in do_execute
File "/usr/lib/python3/dist-packages/ipykernel/zmqshell.py", line 501, in run_cell
File "/usr/lib/python3/dist-packages/IPython/core/interactiveshell.py", line 2717, in run_cell
interactivity=interactivity, compiler=compiler, result=result)
File "/usr/lib/python3/dist-packages/IPython/core/interactiveshell.py", line 2821, in run_ast_nodes
if self.run_code(code, result):
File "/usr/lib/python3/dist-packages/IPython/core/interactiveshell.py", line 2881, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-17-cffbacdceacf>", line 3, in <module>
x_image = tf.placeholder(tf.float32, shape=[None, 15, 50, 1])
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/array_ops.py", line 1332, in placeholder
name=name)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/gen_array_ops.py", line 1748, in _placeholder
name=name)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/op_def_library.py", line 749, in apply_op
op_def=op_def)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py", line 2380, in create_op
original_op=self._default_original_op, op_def=op_def)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py", line 1298, in __init__
self._traceback = _extract_stack()
InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'Placeholder' with dtype float
[[Node: Placeholder = Placeholder[dtype=DT_FLOAT, shape=[], _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
「バニラ」テンソルフローで 2 つのリストを使用すると問題なく動作しますが、TFLearn では動作しません。だから、エラーがどこから来ているのかわからない