日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

Tensorflow遇到的问题InvalidArgumentError: Graph execution error:2 root error(s) found.解决方法

發布時間:2025/4/5 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Tensorflow遇到的问题InvalidArgumentError: Graph execution error:2 root error(s) found.解决方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

文章目錄

  • 遇到問題
  • 解決
  • 參考

遇到問題

平臺google colab
使用GPU
訓練dl模型時,遇到報錯

--------------------------------------------------------------------------- InvalidArgumentError Traceback (most recent call last) <ipython-input-56-09c5afe5a363> in <module>() ----> 1 text_vectorization.adapt(text_only_train_ds)2 3 tfidf_2gram_train_ds = train_ds.map(4 lambda x, y: (text_vectorization(x), y),5 num_parallel_calls=4)3 frames /usr/local/lib/python3.7/dist-packages/tensorflow/python/eager/execute.py in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name)53 ctx.ensure_initialized()54 tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name, ---> 55 inputs, attrs, num_outputs)56 except core._NotOkStatusException as e:57 if name is not None:InvalidArgumentError: Graph execution error:2 root error(s) found.(0) INVALID_ARGUMENT: During Variant Host->Device Copy: non-DMA-copy attempted of tensor type: string[[{{node map/TensorArrayUnstack/TensorListFromTensor/_42}}]][[Func/map/while/body/_1/input/_48/_72]](1) INVALID_ARGUMENT: During Variant Host->Device Copy: non-DMA-copy attempted of tensor type: string[[{{node map/TensorArrayUnstack/TensorListFromTensor/_42}}]] 0 successful operations. 0 derived errors ignored. [Op:__inference_adapt_step_194806]

上述報錯由以下代碼產生

text_vectorization.adapt(text_only_train_ds)tfidf_2gram_train_ds = train_ds.map(lambda x, y: (text_vectorization(x), y),num_parallel_calls=4) tfidf_2gram_val_ds = val_ds.map(lambda x, y: (text_vectorization(x), y),num_parallel_calls=4) tfidf_2gram_test_ds = test_ds.map(lambda x, y: (text_vectorization(x), y),num_parallel_calls=4)model = get_model() model.summary() callbacks = [keras.callbacks.ModelCheckpoint("tfidf_2gram.keras",save_best_only=True) ] model.fit(tfidf_2gram_train_ds.cache(),validation_data=tfidf_2gram_val_ds.cache(),epochs=10,callbacks=callbacks) model = keras.models.load_model("tfidf_2gram.keras") print(f"Test acc: {model.evaluate(tfidf_2gram_test_ds)[1]:.3f}")

解決

目前猜測應該用CPU訓練,而不是GPU。果然,將runtime type改為None即可

因為這里數據預處理使用CPU進行,而具體計算使用GPU,所以數據集應用CPU來做。

參考

https://github.com/tensorflow/tensorflow/issues/28007

總結

以上是生活随笔為你收集整理的Tensorflow遇到的问题InvalidArgumentError: Graph execution error:2 root error(s) found.解决方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。