Я не могу исправить Runtime Errorr - PullRequest
0 голосов
/ 31 марта 2020

Пожалуйста, мне нужна помощь, я продолжаю получать это сообщение об ошибке при запуске моих кодов.

RuntimeError: Попытка захвата EagerTensor без создания функции .

У меня очень мало знаний о программировании и машинном обучении. Буду очень признателен за любую помощь.

y=tf.convert_to_tensor(y)#convert pd.dataframe to tensorflow

Проблема началась, когда я запустил приведенный выше код для преобразования из pandas dataframe в тензорный поток, так как первый также выдавал сообщение об ошибке.

Я могу поставить все коды здесь, если требуется

Это сообщение об ошибке, которое я получил

RuntimeError                              Traceback (most recent call last)
<ipython-input-24-4411ee976a0d> in <module>
      8     cost = sess.run(cost_function, feed_dict={x: X_train, y_: y_train})
      9     cost_history = np.append(cost_history, cost)
---> 10     correct_prediction = tf.equal(tf.argmax(y, 1), tf.argmax(y_, 1))
     11     accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
     12     # print("Accuracy: ", (sess.run(accuracy, feed_dict={x: test_x, y_: test_y})))

~\Anaconda3\lib\site-packages\tensorflow_core\python\util\deprecation.py in new_func(*args, **kwargs)
    505                 'in a future version' if date is None else ('after %s' % date),
    506                 instructions)
--> 507       return func(*args, **kwargs)
    508 
    509     doc = _add_deprecated_arg_notice_to_docstring(

~\Anaconda3\lib\site-packages\tensorflow_core\python\ops\math_ops.py in argmax(input, axis, name, dimension, output_type)
    139   axis = deprecation.deprecated_argument_lookup("axis", axis, "dimension",
    140                                                 dimension)
--> 141   return argmax_v2(input, axis, output_type, name)
    142 
    143 

~\Anaconda3\lib\site-packages\tensorflow_core\python\ops\math_ops.py in argmax_v2(input, axis, output_type, name)
    185   if axis is None:
    186     axis = 0
--> 187   return gen_math_ops.arg_max(input, axis, name=name, output_type=output_type)
    188 
    189 

~\Anaconda3\lib\site-packages\tensorflow_core\python\ops\gen_math_ops.py in arg_max(input, dimension, output_type, name)
    846   _, _, _op, _outputs = _op_def_library._apply_op_helper(
    847         "ArgMax", input=input, dimension=dimension, output_type=output_type,
--> 848                   name=name)
    849   _result = _outputs[:]
    850   if _execute.must_record_gradient():

~\Anaconda3\lib\site-packages\tensorflow_core\python\framework\op_def_library.py in _apply_op_helper(op_type_name, name, **keywords)
    466               dtype=dtype,
    467               as_ref=input_arg.is_ref,
--> 468               preferred_dtype=default_dtype)
    469         except TypeError as err:
    470           if dtype is None:

~\Anaconda3\lib\site-packages\tensorflow_core\python\framework\ops.py in convert_to_tensor(value, dtype, name, as_ref, preferred_dtype, dtype_hint, ctx, accepted_result_types)
   1278       graph = get_default_graph()
   1279       if not graph.building_function:
-> 1280         raise RuntimeError("Attempting to capture an EagerTensor without "
   1281                            "building a function.")
   1282       return graph.capture(value, name=name)

RuntimeError: Attempting to capture an EagerTensor without building a function.

1 Ответ

0 голосов
/ 31 марта 2020

tf.convert_to_tensor не может конвертировать Pandas данных в Tensors. Чтобы загрузить данные из Pandas кадра данных в TensorFlow, обратитесь к следующему руководству:

https://www.tensorflow.org/tutorials/load_data/pandas_dataframe

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...