Lotte Similon
Lotte Similon

Reputation: 61

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

I am trying to make a plot/graph of deep learning model in Keras but it keeps giving me an error which is not very informative.

Here is my code:

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')'''

This is my error message:

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

Upvotes: 2

Views: 2585

Answers (1)

Lotte Similon
Lotte Similon

Reputation: 61

Solved with this code:

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

Upvotes: 2

Related Questions