#python #tensorflow #deep-learning #artificial-intelligence
#python #тензорный поток #глубокое обучение #искусственный интеллект
Вопрос:
Я только начинаю глубокое обучение с помощью tensorflow. Я наткнулся на ann_visualizer и хотел попробовать его. Я следовал руководству по его установке и использованию. Я также установил пакет graphviz и находится в моей исходной папке.
import numpy as np
import pandas as pd
import tensorflow as tf
import keras as keras
data = pd.read_csv('DataSets/Churn_Modelling.csv')
x = data.iloc[: , 3:-1].values
y = data.iloc[: , -1].values
from sklearn.preprocessing import LabelEncoder
le = LabelEncoder()
x[: , 2] = le.fit_transform(x[: , 2])
from sklearn.compose import ColumnTransformer
from sklearn.preprocessing import OneHotEncoder
ct = ColumnTransformer(transformers=[( 'encoder' , OneHotEncoder() , [1])] , remainder='passthrough')
x = ct.fit_transform(x)
from sklearn.model_selection import train_test_split
x_train , x_test , y_train , y_test = train_test_split( x,y , test_size=0.2 , random_state=0)
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
x_train = sc.fit_transform(x_train)
x_test = sc.transform(x_test)
from ann_visualizer.visualize import ann_viz
model = tf.keras.models.Sequential()
model.add(tf.keras.layers.Dense(units=10 , activation='relu'))
model.add(tf.keras.layers.Dense(units=10 , activation='relu'))
model.add(tf.keras.layers.Dense(units=1 , activation='sigmoid'))
ann_viz(model)
Когда я выполняю код, я получаю следующее:
PS D:ANN> amp; C:/Users/hamza/miniconda3/python.exe d:/ANN/ann_model.py
2020-09-26 21:54:07.455336: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found
2020-09-26 21:54:07.456078: 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.
2020-09-26 21:54:09.320246: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library nvcuda.dll
2020-09-26 21:54:09.553112: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1716] Found device 0 with properties:
pciBusID: 0000:02:00.0 name: GeForce MX130 computeCapability: 5.0
coreClock: 1.189GHz coreCount: 3 deviceMemorySize: 4.00GiB deviceMemoryBandwidth: 37.33GiB/s
2020-09-26 21:54:09.554645: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found
2020-09-26 21:54:09.562721: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cublas64_10.dll'; dlerror: cublas64_10.dll not found
2020-09-26 21:54:09.564579: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cufft64_10.dll'; dlerror: cufft64_10.dll not found
2020-09-26 21:54:09.566905: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'curand64_10.dll'; dlerror: curand64_10.dll not found
2020-09-26 21:54:09.568410: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cusolver64_10.dll'; dlerror: cusolver64_10.dll not found
2020-09-26 21:54:09.578061: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cusparse64_10.dll'; dlerror: cusparse64_10.dll not found
2020-09-26 21:54:09.579892: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cudnn64_7.dll'; dlerror: cudnn64_7.dll not found
2020-09-26 21:54:09.581202: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1753] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform.
Skipping registering GPU devices...
2020-09-26 21:54:09.582994: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN)to use the following CPU instructions in performance-critical operations: AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2020-09-26 21:54:09.595543: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x1fad94fed90 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-09-26 21:54:09.596453: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): Host, Default Version
2020-09-26 21:54:09.597665: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1257] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-09-26 21:54:09.598924: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1263]
Traceback (most recent call last):
File "d:/ANN/ann_model.py", line 39, in <module>
ann_viz(model)
File "C:Usershamzaminiconda3libsite-packagesann_visualizervisualize.py", line 42, in ann_viz
input_layer = int(str(layer.input_shape).split(",")[1][1:-1]);
File "C:Usershamzaminiconda3libsite-packagestensorflowpythonkerasenginebase_layer.py", line 2126, in input_shape
raise AttributeError('The layer has never been called '
AttributeError: The layer has never been called and thus has no defined input shape.
Я искал везде и не нашел решения.
Я использую VS Code с Anaconda python
Спасибо!
Ответ №1:
Ваш плотный слой имеет 10 единиц, но Фактическая форма ядра (т. Е. Матрица весов) Не определяется до тех пор, пока не будет определена форма ввода. Например, если бы входные данные имели форму (размер пакета, 20), матрица весов имела бы форму (20, 10), поэтому плотный слой имеет 200 параметров веса. Но до первого вызова модели количество параметров, которые имеет слой, все еще не определено. Поэтому просто вызовите модель один раз, чтобы устранить проблему.
inputs = tf.convert_to_tensor(numpy.random.rand(1,20), dtype='float32')
model(inputs)
ann_viz(model)
Конечно, поскольку вы не обучали модель в своем фрагменте кода, вы просто будете смотреть на случайно инициализированные веса.