【发布时间】:2020-10-31 13:54:33
【问题描述】:
所以,我正在做一个关于 keras 和 tensorflow 基础知识的 LinkedIn 学习课程,因为我对学习这些技术非常感兴趣。然而,设置 TensorFlow 可能是我做过的最痛苦的事情之一。
我在 mac OS 上运行带有 python 3.7 的 Conda 环境只是为了透视。
尝试运行以下代码时;
import pandas as pd
from keras.models import Sequential
from keras.layers import *
training_data_df = pd.read_csv("sales_data_training_scaled.csv")
X = training_data_df.drop('total_earnings', axis=1).values
Y = training_data_df[['total_earnings']].values
# Define the model
model = Sequential()
model.add(Dense(50, input_dim=9, activation='relu'))
model.add(Dense(100, activation='relu'))
model.add(Dense(50, activation='relu'))
model.add(Dense(1, activation='linear'))
model.compile(loss="mean_squared_error", optimizer="adam")
我收到以下错误消息。
ModuleNotFoundError: 没有名为“tensorflow.contrib”的模块
我尝试了很多不同的方法,例如导入 tensorflow.compat.v1 和禁用 v2,但这似乎只会让事情变得更糟。我被卡住了,如果有人可以提供帮助,将不胜感激。
我正在使用 tensorflow 2.0.0 和 keras 2.0.6
将我的导入语句切换到
import pandas as pd
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import *
我不再收到 ModuleNotFound 错误,但是我收到了这个:
Python 3.7.7(默认,2020 年 5 月 6 日,04:59:01) [Clang 4.0.1 (tags/RELEASE_401/final)] 关于达尔文 runfile('/Users/shaneschipper/Desktop/Code/Machine Learning Projects/Ex_Files_Building_Deep_Learning_Apps/Exercise Files/03/create_model final.py', wdir='/Users/shaneschipper/Desktop/Code/Machine Learning Projects/Ex_Files_Building_Deep_Learning_Apps/Exercise Files/ 03') 2020-07-14 09:52:37.558165: I tensorflow/core/platform/cpu_feature_guard.cc:145] 此 TensorFlow 二进制文件使用 Intel(R) MKL-DNN 进行了优化,可在性能关键操作中使用以下 CPU 指令:SSE4。 1 SSE4.2 AVX AVX2 FMA 要在非 MKL-DNN 操作中启用它们,请使用适当的编译器标志重建 TensorFlow。 2020-07-14 09:52:37.558405: I tensorflow/core/common_runtime/process_util.cc:115] 使用默认互操作设置创建新线程池:8. 使用 inter_op_parallelism_threads 进行调整以获得最佳性能。
我不太确定这意味着什么,它可能只是一个警告标志并且可以正常工作,但我不知道。
【问题讨论】:
-
您使用的是什么版本的 tensorflow 和 keras?确保两者兼容。
-
可以分享一下Conda环境的内容吗?
-
Keras:2.0.6,张量流:2.0.0。
标签: python tensorflow machine-learning keras neural-network