簡體   English   中英

AttributeError: 模塊 'keras.utils' 沒有屬性 'plot_model' 但安裝了 Keras 和 tensorflow

[英]AttributeError: module 'keras.utils' has no attribute 'plot_model' but installed Keras and tensorflow

我正在嘗試在 Keras 中繪制深度學習 model 的繪圖/圖表,但它一直給我一個信息量不大的錯誤。

這是我的代碼:

import pandas as pd
forecast_demo = pd.read_csv('forcastdemo.csv')
forecast_demo.head()

X_train = forecast_demo[['index', 'quarter']]
y_train = forecast_demo.revenue
import keras
from tensorflow.keras import Model
from tensorflow.keras import models

from tensorflow.keras.utils import plot_model
from tensorflow.keras.layers import Input, Dense, BatchNormalization
from IPython.core.display import Image

inputs = Input(shape=(2,))              
x = BatchNormalization()(inputs)
x = Dense(512, activation='relu')(x)
x = Dense(128, activation='relu')(x)
x = Dense(64, activation='relu')(x)
x = Dense(32, activation='relu')(x)
outputs = Dense(1)(x)       

model = Model(inputs, outputs)
model.summary()
keras.utils.plot_model(model,to_file='images/oefening2.png', show_shapes=True)
Image('images/oefening2.png')'''

這是我的錯誤信息:

2021-12-26 11:10:25.714969: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2021-12-26 11:10:25.715102: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
2021-12-26 11:10:28.763546: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'nvcuda.dll'; dlerror: nvcuda.dll not found
2021-12-26 11:10:28.763672: W tensorflow/stream_executor/cuda/cuda_driver.cc:269] failed call to cuInit: UNKNOWN ERROR (303)
2021-12-26 11:10:28.766276: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:169] retrieving CUDA diagnostic information for host: PROBOOK17
2021-12-26 11:10:28.766428: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:176] hostname: PROBOOK17
2021-12-26 11:10:28.766711: I tensorflow/core/platform/cpu_feature_guard.cc:151] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
Traceback (most recent call last):
  File "C:\Users\lotte.similon\Documents\datascience\lessen\overzicht_code\oefeningen_ANN.py", line 87, in <module>
    keras.utils.plot_model(model,to_file='images/oefening2.png', show_shapes=True)
AttributeError: module 'keras.utils' has no attribute 'plot_model

使用此代碼解決:

import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import Model

from tensorflow.keras.utils import plot_model
from tensorflow.keras.layers import Input, Dense, BatchNormalization
from IPython.core.display import Image

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM