深度学习是一个引人入胜的研究领域,其技术在解决一系列具有挑战性的机器学习问题方面取得了世界一流的成果。
入门深度学习可能会很困难。
您应该使用哪个库?应该专注于哪些技术?
在这篇文章中,您将通过一个使用易于使用且功能强大的 Keras 库的 Python 深度学习 14 部分速成课程来了解相关知识。
本迷你课程面向已经熟悉 SciPy 生态系统中 scikit-learn 进行机器学习的 Python 机器学习从业者。
通过我的新书《Python 深度学习》,其中包括分步教程和所有示例的Python 源代码文件,助您启动项目。
让我们开始吧。
(提示:您可能想打印或收藏此页面,以便日后参考。)
- **2018 年 3 月更新**:添加了下载数据集的备用链接,因为原始链接似乎已被删除。
- 更新于 2019 年 10 月:已更新至 Keras 2.3.0。

Python 应用深度学习迷你课程
照片由 darkday 提供,保留部分权利。
本迷你课程适合谁?
在我们开始之前,让我们确保你来对了地方。下面的列表提供了一些关于本课程设计对象的一般性指导。
如果您不完全符合这些要点,请不要惊慌,您可能只需要在某个领域稍作补充即可跟上。
- 了解一些代码的开发者。这意味着您可以使用 Python 来完成工作,并知道如何在工作站上设置 SciPy 生态系统(这是一个先决条件)。这并不意味着您是编程大师,但它确实意味着您不惧怕安装软件包和编写脚本。
- 了解一些机器学习知识的开发者。这意味着您了解机器学习的基础知识,如交叉验证、一些算法和偏差-方差权衡。这并不意味着您是机器学习博士,只是您了解相关要点或知道在哪里查找它们。
本迷你课程不是一本深度学习教材。
它将带您从一个了解一些 Python 机器学习知识的开发者,转变为一个能够取得成果并将深度学习的强大功能应用于您自己项目的开发者。
迷你课程概述(可以期待什么)
本迷你课程分为 14 部分。
每节课的设计时间约为普通开发人员 30 分钟。有些您可能会更快完成,有些您可能会选择深入研究并花费更多时间。
您可以根据自己的喜好快速或缓慢地完成每一部分。一个舒适的进度可能是两周内每天完成一课。强烈推荐。
接下来的 14 课将涵盖以下主题
- 第 1 课:Theano 简介。
- 第 2 课:TensorFlow 简介。
- 第 3 课:Keras 简介。
- 第 4 课:多层感知机速成。
- 第 5 课:在 Keras 中开发您的第一个神经网络。
- 第 6 课:将 Keras 模型与 Scikit-Learn 结合使用。
- 第 7 课:绘制模型训练历史。
- 第 8 课:在训练过程中使用检查点保存最佳模型。
- 第 9 课:使用 Dropout 正则化减少过拟合。
- 第 10 课:通过学习率调度提升性能。
- 第 11 课:卷积神经网络速成。
- 第 12 课:手写数字识别。
- 第 13 课:小照片中的对象识别。
- 第 14 课:通过数据增强提高泛化能力。
这将非常有趣。
不过,您需要付出一些努力,阅读、研究和编程。您想学习深度学习,对吧?
(提示:所有这些课程的答案都可以在这个博客上找到,请使用搜索功能)
有任何问题,请在下面的评论中提出。
在评论中分享你的结果。
坚持下去,不要放弃!
Python 深度学习需要帮助吗?
参加我的免费为期两周的电子邮件课程,发现 MLP、CNN 和 LSTM(附代码)。
立即点击注册,还将免费获得本课程的 PDF 电子书版本。
第 1 课:Theano 简介
Theano 是一个用于快速数值计算的 Python 库,可辅助深度学习模型的开发。
Theano 的核心是 Python 中数学表达式的编译器。它知道如何将您的结构转换为非常高效的代码,这些代码使用 NumPy 和高效的原生库,以便在 CPU 或 GPU 上尽可能快地运行。
Theano 表达式的实际语法是符号化的,这可能会让习惯于正常软件开发的初学者望而却步。具体来说,表达式是抽象意义上定义的,经过编译,然后实际用于进行计算。
本课的目标是安装 Theano 并编写一个小型示例,以演示 Theano 程序中符号化的性质。
例如,您可以使用 pip 如下方式安装 Theano
1 |
sudo pip install Theano |
下面是您可以使用的一个小型 Theano 程序示例,可作为起点
1 2 3 4 5 6 7 8 9 10 11 12 13 |
import theano from theano import tensor # 声明两个符号浮点标量 a = tensor.dscalar() b = tensor.dscalar() # 创建一个简单的表达式 c = a + b # 将表达式转换为一个可调用对象,该对象接收 (a,b) 作为输入 # 并计算 c 的值 f = theano.function([a,b], c) # 将 1.5 绑定到 'a',将 2.5 绑定到 'b',并计算 'c' result = f(1.5, 2.5) print(result) |
在 Theano 主页上了解更多关于 Theano 的信息。
第 2 课:TensorFlow 简介
TensorFlow 是 Google 创建和发布的一个用于快速数值计算的 Python 库。与 Theano 类似,TensorFlow 也旨在用于深度学习模型的开发。
凭借 Google 的支持,它可能被用于其部分生产系统,并被 Google DeepMind 研究小组使用,这是一个我们不能忽视的平台。
与 Theano 不同,TensorFlow 更侧重于生产,能够运行在 CPU、GPU 甚至大型集群上。
本课的目标是安装 TensorFlow,并熟悉 TensorFlow 程序中使用的符号表达式的语法。
例如,您可以使用 pip 如下方式安装 TensorFlow
1 |
sudo pip install TensorFlow |
下面是一个您可以使用的小型 TensorFlow 程序示例,可作为起点
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
# TensorFlow 库示例 import tensorflow as tf import tensorflow.compat.v1 as tf tf.disable_v2_behavior() # 声明两个符号浮点标量 a = tf.placeholder(tf.float32) b = tf.placeholder(tf.float32) # 使用 add 函数创建一个简单的符号表达式 add = tf.add(a, b) # 将 1.5 绑定到 'a',将 2.5 绑定到 'b',并计算 'c' sess = tf.Session() binding = {a: 1.5, b: 2.5} c = sess.run(add, feed_dict=binding) print(c) |
在 TensorFlow 主页上了解更多关于 TensorFlow 的信息。
第 3 课:Keras 简介
Theano 和 TensorFlow 的一个难点在于,即使是创建非常简单的神经网络模型也可能需要大量的代码。
这些库的设计初衷主要是作为研究和开发平台,而不是为了实际应用深度学习。
Keras 库通过为 Theano 和 TensorFlow 提供一个包装器来解决这些问题。它提供了一个干净简单的 API,让您只需几行代码即可定义和评估深度学习模型。
由于其易用性以及它利用了 Theano 和 TensorFlow 的强大功能,Keras 正在迅速成为应用深度学习的首选库。
Keras 的重点是模型这一概念。模型生命周期可总结如下
- 定义您的模型。创建一个 Sequential 模型并添加配置好的层。
- 编译您的模型。指定损失函数和优化器,然后调用模型的 compile() 函数。
(同上) - 训练您的模型。通过调用模型的 fit() 函数在数据样本上训练模型。
(同上) - 进行预测。使用模型通过调用模型上的 evaluate() 或 predict() 等函数来对新数据进行预测。
本课的目标是安装 Keras。
例如,您可以使用 pip 如下方式安装 Keras
1 |
sudo pip install keras |
开始熟悉 Keras 库,为接下来的课程做好准备,届时我们将实现我们的第一个模型。
您可以在 Keras 主页上了解更多关于 Keras 库的信息。
第 4 课:多层感知机速成
人工神经网络是一个迷人的研究领域,但入门时可能会让人望而生畏。
(同上)
人工神经网络领域通常被称为神经网络或多层感知机,这也许是因为它们是最有用的神经网络类型。
(同上)
神经网络的基本构建块是人工神经元。它们是简单的计算单元,具有加权的输入信号,并使用激活函数产生输出信号。
(同上)
神经元被组织成神经元网络。一排神经元称为一层,一个网络可以有多层。网络中神经元的结构通常被称为网络拓扑。
(同上)
配置完成后,神经网络需要根据您的数据集进行训练。神经网络的经典且仍然首选的训练算法称为随机梯度下降。
(同上)

简单神经元模型
本课的目标是熟悉神经网络的术语。
深入研究诸如神经元、权重、激活函数、学习率等术语。
第 5 课:在 Keras 中开发您的第一个神经网络
Keras 允许您用极少的代码行来开发和评估深度学习模型。
本课的目标是使用 Keras 库开发您的第一个神经网络。
使用 UCI 机器学习仓库中的标准二元(两类)分类数据集,例如 Pima 印第安人发病糖尿病或 电离层数据集。
将代码组合起来以实现以下目标
- 使用 NumPy 或 Pandas 加载数据集。
- 定义您的神经网络模型并进行编译。
- 用数据集训练您的模型。
- 评估您的模型在未见过的数据上的性能。
为了给您一个巨大的开端,下面是一个完整的可用作起点的可运行示例。
下载数据集并将其放置在您的当前工作目录中。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
from keras.models import Sequential from keras.layers import Dense # 加载数据集 dataset = numpy.loadtxt("pima-indians-diabetes.csv", delimiter=",") X = dataset[:,0:8] Y = dataset[:,8] # 定义和编译 model = Sequential() model.add(Dense(12, input_dim=8, activation='relu')) model.add(Dense(8, activation='relu')) model.add(Dense(1, activation='sigmoid')) model.compile(loss='binary_crossentropy' , optimizer='adam', metrics=['accuracy']) # 拟合模型 model.fit(X, Y, epochs=150, batch_size=10) # 评估模型 scores = model.evaluate(X, Y) print("%s: %.2f%%" % (model.metrics_names[1], scores[1]*100)) |
现在,在另一个数据集上开发您自己的模型,或改编此示例。
在 Keras 简单模型开发 API 上了解更多信息。
第 6 课:将 Keras 模型与 Scikit-Learn 结合使用
scikit-learn 库是 Python 中一个通用机器学习框架,建立在 SciPy 之上。
Scikit-learn 擅长执行诸如评估模型性能和优化模型超参数等任务,仅需几行代码。
Keras 提供了一个包装器类,允许您将深度学习模型与 scikit-learn 结合使用。例如,Keras 中的 KerasClassifier 类的实例可以包装您的深度学习模型,并用作 scikit-learn 中的 Estimator。
在使用 KerasClassifier 类时,您必须指定一个函数名,该函数名可供该类用于定义和编译您的模型。您还可以向 KerasClassifier 类的构造函数传递其他参数,这些参数稍后将传递给 model.fit() 调用,例如 epoch 数和 batch 大小。
本课的目标是开发一个深度学习模型并使用 k 折交叉验证对其进行评估。
例如,您可以像这样定义 KerasClassifier 的实例和用于创建模型的自定义函数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
# 创建模型的功能,KerasClassifier 所必需 def create_model(): # 创建模型 model = Sequential() ... # 编译模型 model.compile(...) return model # 创建用于 scikit-learn 的分类器 model = KerasClassifier(build_fn=create_model, nb_epoch=150, batch_size=10) # 在 scikit-learn 中使用 10 折交叉验证评估模型 kfold = StratifiedKFold(n_splits=10, shuffle=True, random_state=seed) results = cross_val_score(model, X, Y, cv=kfold) |
在 Sciki-Learn API 包装器网页上了解更多关于将 Keras 深度学习模型与 scikit-learn 结合使用的信息。
第 7 课:绘制模型训练历史
通过观察神经网络和深度学习模型在训练过程中的性能变化,您可以了解很多东西。
Keras 提供了在训练深度学习模型时注册回调的功能。
在训练所有深度学习模型时注册的默认回调之一是 History 回调。它记录每个 epoch 的训练指标。这包括损失和准确率(对于分类问题),以及验证数据集的损失和准确率(如果已设置)。
history 对象是从用于训练模型的 fit() 函数调用返回的。指标存储在对象 history 成员的字典中。
本课的目标是检查 history 对象并创建模型在训练期间性能的图表。
例如,您可以像这样打印您的 history 对象收集的指标列表
1 2 3 |
# 列出历史中的所有数据 history = model.fit(...) print(history.history.keys()) |
在 Keras 中的 History 对象和回调 API 上了解更多信息。
第 8 课:在训练过程中使用检查点保存最佳模型
应用程序检查点是一种用于长时运行进程的容错技术。
Keras 库通过回调 API 提供了检查点功能。ModelCheckpoint 回调类允许您定义检查点模型权重的确切位置、文件的命名方式以及进行模型检查点的具体条件。
(同上)
(同上)
检查点有助于在训练过程意外停止时跟踪模型权重。它也有助于跟踪训练过程中观察到的最佳模型。
本课的目标是使用 Keras 中的 ModelCheckpoint 回调来跟踪训练过程中观察到的最佳模型。
您可以定义一个 ModelCheckpoint,它会在每次观察到改进时将网络权重保存到同一个文件。例如
1 2 3 4 5 6 |
from keras.callbacks import ModelCheckpoint ... checkpoint = ModelCheckpoint('weights.best.hdf5', monitor='val_accuracy', save_best_only=True, mode='max') callbacks_list = [checkpoint] # 拟合模型 model.fit(..., callbacks=callbacks_list) |
在 Keras 中的 ModelCheckpoint 回调上了解更多信息。
第 9 课:使用 Dropout 正则化减少过拟合
神经网络的一个大问题是它们可能会过度学习您的训练数据集。
Dropout 是一种简单但非常有效的减少过拟合的技术,在大型深度学习模型中已被证明非常有用。
Dropout 是一种技术,在训练过程中会随机忽略选定的神经元。它们被随机地丢弃。这意味着它们对下游神经元激活的贡献在前向传播中被暂时移除,并且任何权重更新都不会在反向传播中应用于该神经元。
您可以使用 Dropout 层类在深度学习模型中添加 dropout。
本课的目标是试验在神经网络的不同位置添加 dropout,并设置不同的 dropout 概率值。
例如,您可以创建一个 dropout 概率为 20% 的 dropout 层,并像这样将其添加到您的模型中
1 2 3 |
from keras.layers import Dropout ... model.add(Dropout(0.2)) |
在 Keras 中的 dropout 上了解更多信息。
第 10 课:通过学习率调度提升性能
通过使用学习率调度,您通常可以提升模型的性能。
这通常被称为自适应学习率或退火学习率,是一种在训练模型期间改变随机梯度下降所使用的学习率的技术。
Keras 在 SGD 类的随机梯度下降算法实现中内置了基于时间的学习率调度。
在构造该类时,您可以指定衰减率,即每个 epoch 学习率(也指定了)将减少的量。在使用学习率衰减时,您应该增加初始学习率,并考虑添加较大的动量值,例如 0.8 或 0.9。
本课的目标是试验 Keras 中内置的基于时间的学习率调度。
例如,您可以指定一个学习率调度,该调度从 0.1 开始,每个 epoch 衰减 0.0001,如下所示
1 2 3 4 |
from keras.optimizers import SGD ... sgd = SGD(lr=0.1, momentum=0.9, decay=0.0001, nesterov=False) model.compile(..., optimizer=sgd) |
您可以在 此处 了解更多关于 Keras 中 SGD 类的信息。
第 11 课:卷积神经网络速成课
卷积神经网络是一种强大的前馈神经网络技术。
它们通过使用少量输入数据的小方块来学习内部特征表示,从而期望并保留图像中像素之间的空间关系。
特征被学习并应用于整个图像,这使得您图像中的对象可以移动或平移到场景中的其他位置,并且仍能被网络检测到。正是由于这个原因,这种类型的网络对于照片中的对象识别、识别不同方向的数字、面孔、物体等非常有用。
卷积神经网络中有三种类型的层
- 卷积层:由滤波器和特征图组成。
- 池化层:对特征图的激活进行下采样。
- 全连接层:连接在模型末端,可用于进行预测。
在本课中,您将熟悉描述卷积神经网络时使用的术语。
这可能需要您做一些研究。
目前不必过于担心它们的工作原理,只需学习此类网络使用的各种层的术语和配置即可。
第 12 课:手写数字识别
手写数字识别是一个困难的计算机视觉分类问题。
MNIST 数据集 是评估手写数字识别问题算法的标准问题。它包含 60,000 张数字图像,可用于训练模型,以及 10,000 张图像,可用于评估其性能。

MNIST 图像示例
使用卷积神经网络可以在 MNIST 问题上取得最先进的结果。Keras 可以轻松加载 MNIST 数据集。
在本课中,您的目标是为 MNIST 问题开发一个非常简单的卷积神经网络,该网络包含一个卷积层、一个最大池化层和一个用于进行预测的密集层。
例如,您可以使用以下方法在 Keras 中加载 MNIST 数据集
1 2 3 |
from keras.datasets import mnist ... (X_train, y_train), (X_test, y_test) = mnist.load_data() |
下载文件到您的计算机可能需要一些时间。
提示:您将使用的第一个隐藏层 Keras 的 Conv2D 层期望图像数据的格式为 宽度 x 高度 x 通道,而 MNIST 数据有 1 个通道,因为图像是灰度图,宽度和高度均为 28 像素。您可以轻松地将 MNIST 数据集重塑如下
1 2 |
X_train = X_train.reshape((X_train.shape[0], 28, 28, 1)) X_test = X_test.reshape((X_test.shape[0], 28, 28, 1)) |
您还需要对输出类别值进行独热编码,Keras 也提供了一个方便的辅助函数来实现此功能
1 2 3 4 |
from keras.utils import np_utils ... y_train = np_utils.to_categorical(y_train) y_test = np_utils.to_categorical(y_test) |
最后给您一个提示,这里有一个您可以作为起点使用的模型定义
1 2 3 4 5 6 7 8 |
model = Sequential() model.add(Conv2D(32, (3, 3), padding='valid', input_shape=(28, 28, 1), activation='relu')) model.add(MaxPooling2D()) model.add(Flatten()) model.add(Dense(128, activation='relu')) model.add(Dense(num_classes, activation='softmax')) model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy']) |
第 13 课:小照片中的物体识别
物体识别是模型必须指示照片中包含什么的问题。
深度学习模型使用深度卷积神经网络在此类问题上取得最先进的结果。
一个流行的用于评估此类问题模型的标准数据集称为 CIFAR-10。它包含 60,000 张小照片,每张照片包含 10 种物体之一,如猫、船或飞机。

CIFAR-10 图像小样本
与 MNIST 数据集一样,Keras 提供了一个方便的函数,您可以使用它来加载数据集,并且在您第一次尝试加载时,它会将其下载到您的计算机。该数据集为 163 MB,因此下载可能需要几分钟。
您在本课中的目标是为 CIFAR-10 数据集开发一个深度卷积神经网络。我建议采用重复的卷积和池化层模式。考虑尝试 dropout 和长时间训练。
例如,您可以使用以下方法在 Keras 中加载 CIFAR-10 数据集并为其准备用于卷积神经网络
1 2 3 4 5 6 7 8 9 10 11 |
from keras.datasets import cifar10 from keras.utils import np_utils # 加载数据 (X_train, y_train), (X_test, y_test) = cifar10.load_data() # 将输入从 0-255 归一化到 0.0-1.0 X_train = X_train.astype('float32') X_test = X_test.astype('float32') X_train = X_train / 255.0 X_test = X_test / 255.0 # one hot 编码输出 y_train = np_utils.to_categorical(y_train) y_test = np_utils.to_categorical(y_test) |
第 14 课:通过数据增强提高泛化能力
在使用神经网络和深度学习模型时,需要进行数据准备。
在更复杂的物体识别任务中, 数据增强的需求也越来越大。这是指对数据集中图像进行随机翻转和移位修改。这实质上使您的训练数据集更大,并帮助您的模型泛化图像中对象的_位置_和_方向_。
Keras 提供了一个图像增强 API,它可以在使用时创建数据集图像的修改版本。 ImageDataGenerator 类可用于定义要执行的图像增强操作,这些操作可以适应数据集,然后用于代替您的数据集来训练模型。
您本课的目标是使用您从之前的课程(如 MNIST 或 CIFAR-10)中已经熟悉的某个数据集来尝试 Keras 图像增强 API。
例如,下面的示例创建了 MNIST 数据集中图像的最大 90 度随机旋转。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# 随机旋转 from keras.datasets import mnist from keras.preprocessing.image import ImageDataGenerator from matplotlib import pyplot # 加载数据 (X_train, y_train), (X_test, y_test) = mnist.load_data() # 重塑为 [样本][像素][宽度][高度] X_train = X_train.reshape((X_train.shape[0], 28, 28, 1)) X_test = X_test.reshape((X_test.shape[0], 28, 28, 1)) # 转换为浮点数 X_train = X_train.astype('float32') X_test = X_test.astype('float32') # 定义数据准备 datagen = ImageDataGenerator(rotation_range=90) # 从数据拟合参数 datagen.fit(X_train) # 配置批次大小并检索一个图像批次 for X_batch, y_batch in datagen.flow(X_train, y_train, batch_size=9): # 创建一个 3x3 的图像网格 for i in range(0, 9): pyplot.subplot(330 + 1 + i) pyplot.imshow(X_batch[i].reshape(28, 28), cmap=pyplot.get_cmap('gray')) # 显示图表 pyplot.show() break |
您可以在 此处 了解更多关于 Keras 图像增强 API 的信息。
深度学习迷你课程回顾
恭喜,你做到了。干得好!
花点时间回顾一下你已经走了多远:
- 您了解了 Python 中的深度学习库,包括强大的数值计算库 Theano 和 TensorFlow,以及易于使用的 Keras 库,用于应用深度学习。
- 您使用 Keras 构建了第一个神经网络,并学会了如何将深度学习模型与 scikit-learn 结合使用,以及如何检索和绘制模型的训练历史。
- 您了解了如 dropout 正则化和学习率调度等更高级的技术,以及如何在 Keras 中使用这些技术。
- 最后,您更进一步,学习并开发了用于复杂计算机视觉任务的卷积神经网络,并了解了图像数据的增强。
不要小看这些成就,您在短时间内取得了长足的进步。这只是您 Python 深度学习之旅的开始。请继续练习和发展您的技能。
您喜欢这个迷你课程吗?您有任何问题或困惑的地方吗?
留下评论,让我知道。
每课内容太少了
嗯,这是一个迷你课程,不是大学课程。
亲爱的 Jason。
我非常欣赏您的努力。课程很棒。我有一个关于课程中缺失部分的问题。那就是如何使用模型。我根据第 6 课构建了模型。我训练并调整了模型。我的问题是,当我拥有新的输入数据时,我应该使用什么函数让模型预测值?通常 model.predict 应该可以工作。但这个模型却不行。您能给我一些建议吗!我们该如何做到。
谢谢
谢谢。
您可以使用 model.predict() 对新数据进行预测,在此处了解更多信息
https://machinelearning.org.cn/make-predictions-scikit-learn/
嗨 Jason,您使用什么硬件?您使用性能强大的笔记本电脑吗?
对于大型模型,我使用 AWS 上的 GPU。
https://machinelearning.org.cn/develop-evaluate-large-deep-learning-models-keras-amazon-web-services/
我的工作站和笔记本电脑都是运行 OS X 的 Mac。
我以为一台配置更强大的本地机器,带有 i7、16GB RAM、4GB CUDA GPU 就足够了,所以即使我不使用 AWS,我是否应该没有问题?
这看起来很棒。
如果您需要更多 RAM 或想同时运行两个模型,AWS 始终可用。或者,几年后他们可能会提供更大的 GPU 实例,您可能需要访问。
亲爱的
很抱歉,我无法下载深度学习迷你课程文件和其他文件。我该怎么办?
很遗憾听到这个消息 Seyed,通常它会立即通过电子邮件发送给您。也许它落入了其他文件夹?
我刚给您发了一封直接邮件,附件是 PDF。
亲爱的布朗利博士
为什么我们要在同一个训练集(X,Y)上评估模型?这与其他从不使用训练数据进行评估的机器学习模型是否有些不同?
这只是一个例子。
在第 02 课:TensorFlow 入门中
result 未定义
将 result 改为 c
谢谢,已修复!
Jason,
我正在学习第 7 章深度学习书籍中的代码。我遇到了两个问题。
1. 当使用 np.loadtxt() 函数加载数据时,我遇到以下错误:ValueError: could not convert string to float: ‘column_a’。
我改用 np.genfromtxt() 函数加载了数据,并继续执行代码,直到在训练模型时遇到第二个错误
2. acc: nan
Epoch 28/150
768/768 [==============================] – 0s 122us/step – loss: nan – acc: 0.0000e+00
Epoch 29/150
768/768 [==============================] – 0s 125us/step – loss: nan – acc: 0.0000e+00
Epoch 30/150
768/768 [==============================] – 0s 159us/step – loss: nan – acc: 0.0000e+00
我不确定问题出在哪里。有什么关于我哪里出错的评论吗?
谢谢,
RA
也许您需要更新您的库?
也许您可以尝试运行书中提供的代码文件?
请通过此页面或电子邮件(联系页面)告知我您的进展。
在第 12 课中,您写道 Conv2D 期望数据的格式为 channels x width x height。但在这里 https://keras.org.cn/layers/convolutional/#conv2d,channel 参数放在最后。我说得对吗?
是的。
感谢您的快速回复!此外,我非常感谢这个网站。它对我帮助很大!
不客气。
你好,我是一名高中生,正在学习并行处理和计算机科学,应用深度学习与超立方体有什么关系?
深度学习是一个研究领域。
超立方体是几何学中的一个概念,例如,在超过 3 个维度中的立方体。
你好,
是否有 tensorflow 2 类似的资料?
谢谢!
我主要使用独立的 Keras,但如果您愿意,可以将所有示例改编为 tf.keras。
感谢您发送课程详情。
我已经安装了 theano 并执行了代码。
它有效。
谢谢你。
干得好!
嗨 Jason,在第 04 课中我遇到了一个问题。
我已将 pima-indians-diabetes 数据库的链接内容复制到一个 Excel 文件中,并将其保存为 .csv(允许的 4 种不同的 .csv 格式),然后在 Anaconda 提示符下运行代码时,它总是给我一个错误
File “neuralnetwork_keras.py”, line 5, in
dataset = numpy.loadtxt(“pima-indians-diabetes.csv”, delimiter=’,’)
NameError: name ‘numpy’ is not defined
我已经安装了 numpy(我通过 pip install numpy 进行了检查)。为什么它显示“name ‘numpy’ is not defined”?
错误提示 numpy 未安装,或者如果安装了,它在您的 anaconda 提示符下不可用。
从同一个提示符,也许可以尝试再次安装它,然后重新启动机器?
亲爱的杰森,
首先,我想感谢您提供在线课程。
我有一个问题,我构建了一个基于第 6 课的模型,我训练了数据等等。现在我想用它来预测新数据集的值,我应该使用什么函数?
我尝试使用 model.predict,但它不起作用。
………………………………………
这是脚本
来自 keras.models import Sequential
from keras.layers import Dense
from keras.wrappers.scikit_learn import KerasRegressor
from sklearn.model_selection import cross_val_score
from sklearn.model_selection import KFold
from sklearn.preprocessing import StandardScaler
from sklearn.pipeline import Pipeline
import numpy
import timeit
import pandas as pd
start = timeit.default_timer()
names = [‘WOB’, ‘RPM’, ‘ROP’, ‘SPP’,’Flow’ ,’Flow2′]
inputdata = pd.read_csv(“Input5.csv”, names=names)
dataset = inputdata.values
X = dataset[:,0:5]
Y = dataset[:,5]
test_data= dataset[:,0:5]
seed = None
numpy.random.seed(seed)
def baseline_model()
# 创建模型
model = Sequential()
model.add(Dense(10, input_dim=5, kernel_initializer=’normal’, activation=’relu’))
model.add(Dense(10, kernel_initializer=’normal’, activation=’relu’))
model.add(Dense(1, kernel_initializer=’normal’))
# 编译模型
model.compile(loss='mean_squared_error', optimizer='adam')
return model
estimator = KerasRegressor(build_fn=baseline_model, nb_epoch=100, batch_size=10, verbose=0)
kfold = KFold(n_splits=2, random_state=seed)
results = cross_val_score(estimator, X, Y, cv=kfold)
Predicted_Value=model.predict(test_data)
print(“Baseline: %.2f (%.2f) MSE” % (results.mean(), results.std()))
stop = timeit.default_timer()
print(‘Time: ‘, stop – start)
……………………………………………………..
希望我能得到您的帮助
这将帮助您为新数据进行预测
https://machinelearning.org.cn/make-predictions-scikit-learn/
768/768 [==============================] – 0s 32us/step
accuracy: 73.31%
谢谢
干得好!
Greetings of the day sir
How to predict Uncertainty in neural networks?
Neural nets will predict the probability of a class label (uncertainty) by default.
To predict uncertainty for a numeric value in a regression problem, you can fit multiple final models and use them to get a distribution of expected values – a quick and dirty prediction interval.
lesson 02 example give me a warning that point here
https://tensorflowcn.cn/api_docs/python/tf/compat/v1/disable_resource_variables
suggestions to avoid it?
干得漂亮!
“Great work!” …was only a note….. mmmm … ????
… maybe you trained an LSTM to answer some common comments? ????
anyway,
谢谢
Hahah, not yet!
嗨,Jason,
I am running the code examples of Chapter 7 “Evaluate The performance of Deep Learning Models” of your book “Deep Learning With Python.
I get the following results
a) for automatic verification: val_accuracy: 0.7717
b) for manual verification: val_accuracy: 0.7874
c) for manual k-fold Cross validation: 70.30% (+/- 6.05%)
You write in your book that “The gold standard for machine learning model evaluation is k-fold cross-validation”.
So I don’t understand why it’s with k-fold cross validation that I get the worst result :=(
Do you have any idea why I get the opposite results to your statement?
谢谢,
诚挚的问候,
Dominique
It may be a worse result, but it is likely a better estimate of the true performance of the model compared to other methods.
嗨,Jason,
Thank you very much for your answer that makes sense now.
Dominique
不客气。
嗨,Jason,
In chapter 8 “Use Keras Models with Scikit-Learn For General Machine Learning” of your book “Deep Learning With Python”.
When I run the Grid search Neural network, the time of execution is 42 minutes. That’s a bit long as you say in your book it should take 5 minutes.
I am running the code on a recent iMac with a CPU 3Ghz Intel core i5 6 coeurs with macOS Catalina.
It’s true that when the program starts I get the message “Your CPU supports instructions that this TensorFlow binary was not compile to use: AX2 FMA.”
I have installed TensorFlow with anaconda: conda install -c conda-forge tensor flow
Do you have any suggestion for having a better speed of execution?
谢谢,
诚挚的问候,
Dominique
One approach might be to run it on AWS EC2 with GPU support.
嗨,Jason,
thanks for your answer. I will try.
祝你好运!
嗨,Jason,
In Chapter 11 “Project: Regression Of Boston House Prices” of you book “Deep Learning With Python”, I got the following results
I do not see any major differences between Larger and Wider but a clear improvement with the Standardization.
Thanks for these very didactic examples.
But I note that the examples with HostonHousing or Iris already take time to execute and I consider them as small set of data. So for biggest dataset obviously the need for more CPU/GPU/TFU hardware is mandatory.
May I ask you a question?
I would like to know if it is worthwhile to invest, as an individual, in renting AWS EC2 GPU power to run your examples in the book? isn’t it too costly?
谢谢,
诚挚的问候,
Dominique
干得好!
I recommend start by renting time, it is very cheap when getting started. You don’t need a large/powerful instance to get a lot of improvement.
Also, many readers use google colab which is free. I don’t know much about it.
嗨,Jason,
Thanks for the Colab tip.
I had a quick try for the wider example.
On Colab: 1’27”
On my iMac: 58″
I will compare later for more complex examples. I have no doubt that Google GPUs are faster than my iMac :=) By the way there is a link on how to upload the local file like the data set for example
https://medium.com/@master_yi/importing-datasets-in-google-colab-c816fc654f97
诚挚的问候,
Dominique
干得好!
嗨,Jason,
For lesson 9 “Reduce Overfitting with Dropout regularization” of your Book “Deep Learning with Python”, I got the following results with the code provide in your book
Baseline: a) 84,05% (8,23%) b) 85,50% (10,07%)
Dropout on visible layer a) 87,95% (7,20%) b) 87,00% (6,12%)
Dropout hidden layers a) 83,60% (8,51%) b) 87,52% (5,25%)
It seems dropout has the best effect when used only on the visible layer.
诚挚的问候,
Dominique
干得好!
嗨,Jason,
About Chapter 18 “Project Handwritten Digit Recognition” of your Book “Deep Learning with Python”, I got the following results
Your book is very cool. We can progress steadily and see concrete results.
谢谢,
Dominique
干得好!
嗨,Jason,
About Chapter 20 “Project Object Recognition in Photographs” of your book “Deep Learning with Python”, I got the following results
Better accuracy comes at the expense of execution time :=) I will have to move to Colab or AWS.
I have a question that I think I am not the only one on this planet that is asking for: I have a full set of photographies on my computer for which I would like to regroup by classification based on face recognition. Do you have any suggestion for a source of information?
谢谢,
诚挚的问候,
Dominique
Yes, you can use face detection and then train a face recognition system. I show exactly how in this book
https://machinelearning.org.cn/deep-learning-for-computer-vision/
Also, I think this type of feature is probably built into photo management software these days.
嗨,Jason,
谢谢。
I had a try on Google Colab for the “Large CNN CIFAR 10” and it’s amazing. The test runs in 6 minutes (after selection of GPU in the notebook parameter) compared to 1 hour on my iMac (which is recent). With an accuracy of 77,80%.
But with the TFU option Google Colab, the test is too long from the very first epoch.
Do you have an idea why TFU is of any help?
谢谢,
诚挚的问候,
Dominique
Sorry, I don’t know about colab or tpus.
嗨 Jason
Just tried lesson number 5, and it goes very well.
Trying to do some of my own I built a database with two coluns
First column secuencial numbers from 1 to 500, second column 3 times first column
The answer to this is obvius y= 3 *x
Modified the program and obtained the following, that seems to me it i not working
Loss = 753758,9960
accuracy = 0.00%
What is it that I am doing wrong ?
The modified program is
# -*- coding: utf-8 -*-
"""
Spider Editor
Created on Thu May 21 12:04:05 2020
@author: Caro Sertorio
DATABASE USEDbuilt as follows
X data is correlative number 500
Y data is correlative 3 times column x
a csv table with functio y=f(x) being y=3*x
np.shape(dataset) is tuple dimension = (499,2)
"""
来自 keras.models import Sequential
from keras.layers import Dense
import numpy as np
import pandas as pd
# 加载数据集
dataset= pd.read_csv(‘C:/Neural/Data/Tabla x 3.csv’,sep=’;’,header=0)
dataset = dataset.values
X = dataset[:,0]
Y = dataset[:,1]
# 定义和编译
model = Sequential()
model.add(Dense(1, input_dim=1, activation=’relu’))
# model.add(Dense(10, activation=’relu’))
model.add(Dense(1, activation=’relu’))
model.compile(loss=’mean_squared_error’ , optimizer=’adam’, metrics=[‘accuracy’])
# 拟合模型
model.fit(X, Y, epochs=10, batch_size=5)
# 评估模型
scores = model.evaluate(X, Y)
print(“%s: %.2f%%” % (model.metrics_names[1], scores[1]*100))
Hope you can comment
此致
干得好!
You cannot use relu in the activation function for the output layer. For regression use linear. Also, you cannot use accuracy for regression.
嗨,Jason,
i have just finished your book “Deep Learning With Python”. I found it excellent as the previous one I read “Machine Learning Mastery with R”. I would advise any reader of your blog to buy those books. For me it speeds up my learning curve.
I published a post on my blog summarizing my experience of your book.
http://questioneurope.blogspot.com/2020/05/deep-learning-with-python-jason-brownlee.html
Thanks very much for all the progress I got up to your books.
诚挚的问候,
Dominique
Thanks Dominique!
Writing summaries like you have done is the best way to crystallize what you have learned, great work!
嗨,Jason,
Today I run your example of code “Text Generation With Alice in Wonderland” you provide in your book “Deep Learning With Python”.
In fact I replace “Alice in Wonderland” with a famous title from Victor Hugo (a famous French writer) “Les misérables”.
The total number of characters was 625 332. It took about 6h30 to train the model on my iMAC. But I admit that I was really surprised by the results!
I published a post to summarize my findings
http://questioneurope.blogspot.com/2020/05/les-miserables-de-victor-hugo-la-sauce.html
Again thanks for your book,
诚挚的问候,
Dominique
Well done, very impressive!
第二课
In this lesson, your goal is to install TensorFlow become familiar with the syntax of the symbolic expressions used in TensorFlow programs.
For example, you can install TensorFlow using pip. There are many different versions of TensorFlow, specialized for each platform. Select the right version for your platform on the TensorFlow installation webpage.
下面是一个您可以使用的小型 TensorFlow 程序示例,可作为起点
When I tried after installing tensorflow, warning message has appeared as follows
n error ocurred while starting the kernel
Warning! ***HDF5 library version mismatched error***
The HDF5 header files used to compile this application do not match
the version used by the HDF5 library to which this application is linked.
Data corruption or segmentation faults may occur if the application continues.
This can happen when an application was compiled by one version of HDF5 but
linked with a different version of static or shared HDF5 library.
You should recompile the application or check your shared library related
settings such as ‘LD_LIBRARY_PATH’.
You can, at your own risk, disable this warning by setting the environment
variable ‘HDF5_DISABLE_VERSION_CHECK’ to a value of ‘1’.
Setting it to 2 or higher will suppress the warning messages totally.
Headers are 1.10.4, library is 1.10.5
SUMMARY OF THE HDF5 CONFIGURATION
=================================
General Information
‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑
HDF5 Version: 1.10.5
Configured on: 2019????????
Configured by: Visual Studio 15 2017 Win64
Host system: Windows????.0.17763
Uname information: Windows
Byte sex: little‑endian
Installation point: C:/Program Files/HDF5
Compiling Options
‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑
Build Mode
Debugging Symbols
Asserts
Profiling
Optimization Level
Linking Options
‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑
库
Statically Linked Executables: OFF
LDFLAGS: /machine:x64
H5_LDFLAGS
AM_LDFLAGS
Extra libraries
Archiver
Ranlib
Languages
‑‑‑‑‑‑‑‑‑‑
C: yes
C Compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x64/cl.exe 19.16.27027.1
CPPFLAGS
H5_CPPFLAGS
AM_CPPFLAGS
CFLAGS: /DWIN32 /D_WINDOWS /W3
H5_CFLAGS
AM_CFLAGS
Shared C Library: YES
Static C Library: YES
Fortran: OFF
Fortran Compiler
Fortran Flags
H5 Fortran Flags
AM Fortran Flags
Shared Fortran Library: YES
Static Fortran Library: YES
C++: ON
C++ Compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x64/cl.exe 19.16.27027.1
C++ Flags: /DWIN32 /D_WINDOWS /W3 /GR /EHsc
H5 C++ Flags
AM C++ Flags
Shared C++ Library: YES
Static C++ Library: YES
JAVA: OFF
JAVA Compiler
特征
‑‑‑‑‑‑‑‑‑
Parallel HDF5: OFF
Parallel Filtered Dataset Writes
Large Parallel I/O
High‑level library: ON
Threadsafety: OFF
Default API mapping: v110
With deprecated public symbols: ON
I/O filters (external): DEFLATE DECODE ENCODE
MPE
Direct VFD
dmalloc
Packages w/ extra debug output
API Tracing: OFF
Using memory checker: OFF
Memory allocation sanity checks: OFF
Function Stack Tracing: OFF
Strict File Format Checks: OFF
Optimization Instrumentation
Bye…
Can you please help me.
也许这会有帮助。
https://tensorflowcn.cn/install
你好,
Lesson 5: am getting error numpy is not defined
Can anyone help me
You need to install numpy
https://machinelearning.org.cn/setup-python-environment-machine-learning-deep-learning-anaconda/
第 1 课:Theano 简介
the output for the result variable is 4.0
干得好!
第 2 课:TensorFlow 简介
output for c : 4.0
干得好!
嗨,Jason,
its my first day to start with theano.
I have run the code in colab and found the result of two variables sum of a and b is 4 .
kind regards
mamun
干得好!
嗨,Jason,
I got the error below in Lesson 06. Could you help me, please?
谢谢。
NameError Traceback (最近一次调用)
in
10
11 # create classifier for use in scikit-learn
—> 12 model = KerasClassifier(build_fn=create_model, epochs=150, batch_size=10)
13 # evaluate model using 10-fold cross validation in scikit-learn
14 kfold = StratifieldKFolder(n_splits=10, shuffle=True, randon_state=seed)
NameError: name ‘KerasClassifier’ is not defined
The error suggest that Keras is not installed or that you have not imported the class (e.g. skipped some lines).
谢谢。
嗨,Jason,
Here you can see the output of lesson 6
0.7267259001731873
The result appear with some delay. Is it normal?
谢谢,
Francisco
干得不错。
Yes. It may take time to complete the model evaluation.
安装 Theano
I typed pip installed Theano into the Anaconda powershell and it seemed to work
Then in Anaconda, I typed
import theano
from theano import tensor
并收到了以下警告
警告 (theano.configdefaults): g++ 不可用,如果使用 conda: `conda install m2w64-toolchain`
C:\Program Files\Anaconda3\lib\site-packages\theano\configdefaults.py:560: UserWarning: DeprecationWarning: there is no c++ compiler.This is deprecated and with Theano 0.11 a c++ compiler will be mandatory
warnings.warn("DeprecationWarning: 没有 c++ 编译器。"
WARNING (theano.configdefaults): g++ not detected ! Theano will be unable to execute optimized C-implementations (for both CPU and GPU) and will default to Python implementations. Performance will be severely degraded. To remove this warning, set Theano flags cxx to an empty string.
“dot” with args [‘-Tps’, ‘C:\\Users\\gpautsch\\AppData\\Local\\Temp\\tmpuavj5jyx’] returned code: 1
stdout, stderr
b”
b”
警告 (theano.tensor.blas): 使用基于 NumPy C-API 的实现来处理 BLAS 函数。
然后,我输入了您建议的其余代码,并且奏效了
# 声明两个符号浮点标量
a = tensor.dscalar()
b = tensor.dscalar()
# 创建一个简单的表达式
c = a + b
# 将表达式转换为一个可调用对象,该对象接收 (a,b) 作为输入
# 并计算 c 的值
f = theano.function([a,b], c)
# 将 1.5 绑定到 'a',将 2.5 绑定到 'b',并评估 'c'
result = f(1.5, 2.5)
print(result)
结果是 4.0
我应该对这个警告做些什么吗?
也许暂时忽略警告。
许多新库都会向控制台输出大量内容 – 我认为这是一种糟糕的做法。
嗨,Jason,
Here you can see the output of lesson 6
0.7267259001731873
The result appear with some delay. Is it normal?
谢谢,
Francisco
嗨,Jason,
Lesson2: Introduction to TensorFlow
答案是 4.0
对于第一课,我遇到了报错
回溯(最近一次调用)
File “theano.py”, line 1, in
import theano
File “C:\Users\Azerul Azlan\pillow\theano.py”, line 2, in
from theano import tensor
ImportError: cannot import name ‘tensor’ from ‘theano’
如何修复?
您可能需要更新您的 theano 版本?
如何更新 theano?
如下
Numpy Error in Lesson 05: Develop Your First Neural Network in Keras
下面的几行将解决它
import numpy as np
# 加载数据集
dataset = np.loadtxt(“pima-indians-diabetes.csv”, delimiter=”,”)
很遗憾听到您遇到了错误。
感谢分享。
4.0
Lesson 2: 我得到的答案是
又是 4.0
干得好。
嗨,Jason,
除了 4.0,我还收到了以下信息,这是 Lesson 2 的输出
2021-01-29 11:15:29.911385: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2021-01-29 11:15:29.917569: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 1996245000 Hz
2021-01-29 11:15:29.919781: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x4699070 executing computations on platform Host. Devices
2021-01-29 11:15:29.919852: I tensorflow/compiler/xla/service/service.cc:175] StreamExecutor device (0): ,
2021-01-29 11:15:29.924075: W tensorflow/compiler/jit/mark_for_compilation_pass.cc:1412] (One-time warning): Not using XLA:CPU for cluster because envvar TF_XLA_FLAGS=–tf_xla_cpu_global_jit was not set. If you want XLA:CPU, either set that envvar, or use experimental_jit_scope to enable XLA:CPU. To confirm that XLA is active, pass –vmodule=xla_compilation_cache=1 (as a proper command-line flag, not via TF_XLA_FLAGS) or set the envvar XLA_FLAGS=–xla_hlo_profile.
干得不错。
您现在可以忽略这些警告。
嗨,Jason,
在遵循课程 3 之前,我尝试了以下网站上的几个示例。
https://keras.org.cn/examples/
我必须说这很有趣,因为我学到了一些关于定义 Keras 模型和添加配置层的东西。
感谢您要求我在遵循课程 3 之前尝试一下。
Kapila
谢谢。
尊敬的 Jason,
我完成了第 5 课。我也会尝试用我的想法来做。我的准确率是 79.56%。不过,我包含了以下导入 numpy 的行,当然我也修改了 nump.loadtxt 的行使其成为 np.loadtxt。哦,我几乎忘了我必须像下面所示那样修改以下两行
来自 keras.models import Sequential
from keras.layers import Dense
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
此致
Kapila
这些更改不是必需的,但它们工作得很好。
嗨,Jason,
我完成了第二课(TensorFlow)
import tensorflow as tf
import tensorflow.compat.v1 as tf
(No module named ‘compat’)
我将其替换为
import tensorflow._api.v2.compat.v1 as tf
现在我开始工作了,但只有一个警告“Access to a protected member _api of a class”。
您对“No module named ‘compat’”有什么建议吗?
谢谢!
很遗憾听到您遇到这个问题,您能检查一下您正在使用的 TensorFlow 版本吗?
TensorFlow 版本是 2.4.1。
谢谢帮助。
干得好!
嗨,Jason,
Day 2 的 TensorFlow 安装网页的链接显示 404 错误。
https://tensorflowcn.cn/versions/r0.9/get_started/os_setup.html?__s=9xcgqo9bstyw6m69ilwy
你能帮忙吗?
链接似乎可以正常工作。
试试这个
https://tensorflowcn.cn/
Day 1 和 Day 2 都已完成。
Day 2 花了一些时间安装 TensorFlow… 终于成功了。
干得好!
Day 1 完成。谢谢
干得好!
你好 Jason,
我将我的代码和日志放在:https://github.com/CBrauer/Jason-Brownlee-Class-code
查尔斯
干得好!
嗨,Jason,
在 Lesson #1 中,在 IDLE 中运行 Python 3.9 时,我收到一个警告,即没有 c++ 编译器
警告 (theano.configdefaults): g++ 不可用,如果使用 conda: `conda install m2w64-toolchain`
警告(来自警告模块)
File “C:\Users\Ramseys Laptop\AppData\Local\Programs\Python\Python39\lib\site-packages\theano\configdefaults.py”, line 560
warnings.warn("DeprecationWarning: 没有 c++ 编译器。"
UserWarning: DeprecationWarning: there is no c++ compiler.This is deprecated and with Theano 0.11 a c++ compiler will be mandatory
WARNING (theano.configdefaults): g++ not detected ! Theano will be unable to execute optimized C-implementations (for both CPU and GPU) and will default to Python implementations. Performance will be severely degraded. To remove this warning, set Theano flags cxx to an empty string.
警告 (theano.tensor.blas): 使用基于 NumPy C-API 的实现来处理 BLAS 函数。
有什么想法吗?此致,Ramsey。
也许这些警告可以安全地忽略?
嗨,Jason,
L#1:忽略我之前的警告后,我认为我得到了预期的答案。谢谢。
L#2:使用您的链接“TensorFlow installation webpage”,我遇到了 http 404 错误。
链接是:https://tensorflowcn.cn/versions/r0.9/get_started/os_setup.html?__s=og671j1sv022kbpymsk5 但 TensorFlow 网站没有 r0.9 版本。
在我收到您的回复之前,我将尝试使用 r1.15(最低可用版本)。
此致,Ramsey(1975 年我在墨尔本工作了一年)。
谢谢,这可能会有帮助
https://machinelearning.org.cn/setup-python-environment-machine-learning-deep-learning-anaconda/
在得到 4 的结果之前,我收到了以下消息。看起来有些不对。你能给些评论吗?
python: can’t open file ‘anntensorflow.py’: [Errno 2] No such file or directory
(base) jupitersitorus@jupiters-MacBook-Air ~ % cd kodepython
(base) jupitersitorus@jupiters-MacBook-Air kodepython % python anntensorflow.py
WARNING:tensorflow:From /Users/jupitersitorus/opt/anaconda3/lib/python3.8/site-packages/tensorflow/python/compat/v2_compat.py:96: disable_resource_variables (from tensorflow.python.ops.variable_scope) is deprecated and will be removed in a future version.
Instructions for updating
non-resource variables are not supported in the long term
2021-04-23 19:44:56.315571: I tensorflow/compiler/jit/xla_cpu_device.cc:41] Not creating XLA devices, tf_xla_enable_xla_devices not set
2021-04-23 19:44:56.318623: 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 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2021-04-23 19:44:56.324443: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:196] None of the MLIR optimization passes are enabled (registered 0 passes)
4.0
也许可以将您的错误和代码发布到 stackoverflow?
非常好,非常棒……时间很短,但结果很好……
谢谢。
非常好,非常棒……时间很短,但结果很好……但我是在 Google Club 上运行的……第一个课程的答案是…… 4.0
干得好。
阅读并执行了 Lesson 01 和 02 的代码,答案是 4.0
干得好。
奇怪的是——也是 4 🙂
但是我收到了一些警告
UserWarning: DeprecationWarning: there is no c++ compiler. This is deprecated and with Theano 0.11 a c++ compiler will be mandatory
warnings.warn("DeprecationWarning: 没有 c++ 编译器。"
WARNING (theano.configdefaults): g++ not detected ! Theano will be unable to execute optimized C-implementations (for both CPU and GPU) and will default to Python implementations. Performance will be severely degraded. To remove this warning, set Theano flags cxx to an empty string.
警告 (theano.tensor.blas): 使用基于 NumPy C-API 的实现来处理 BLAS 函数。
我该怎么办?
你可能可以忽略这些警告。
如果你能展示如何使用自己的数据集而不是 MNIST 数据集来运行 CNN,那就太好了?
是的,博客上有很多,从这里开始
https://machinelearning.org.cn/start-here/#dlfcv
嗨,Jason,
感谢您对深度学习基础的快速回顾。它结构良好,易于阅读和遵循。
在下一门迷你课程中加入 RNN 章节会很好。
谢谢
谢谢。
这是一门关于 LSTMs 的课程
https://machinelearning.org.cn/long-short-term-memory-recurrent-neural-networks-mini-course/
这是另一个
https://machinelearning.org.cn/how-to-get-started-with-deep-learning-for-time-series-forecasting-7-day-mini-course/
Lesson_01-Introduction-to-Theano 的结果
结果似乎是正确的,但充满了警告!!我的运行基于 Python 3.7,通过 PyCharm
有什么帮助吗?
警告 (theano.configdefaults): g++ 不可用,如果使用 conda: `conda install m2w64-toolchain`
WARNING (theano.configdefaults): g++ not detected ! Theano will be unable to execute optimized C-implementations (for both CPU and GPU) and will default to Python implementations. Performance will be severely degraded. To remove this warning, set Theano flags cxx to an empty string.
警告 (theano.tensor.blas): 使用基于 NumPy C-API 的实现来处理 BLAS 函数。
4.0
Process finished with exit code 0
应该没事的。这些警告不会对您的结果产生任何不利影响。
Lesson_02-introduction-to-tensorflow 的结果
结果似乎是正确的,但充满了警告!!我的运行基于 Python 3.7,通过 PyCharm
有什么帮助吗?
2021-11-05 13:44:06.853373: 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-11-05 13:44:06.853726: 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.
WARNING:tensorflow:From C:\Users\cveig\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\compat\v2_compat.py:101: disable_resource_variables (from tensorflow.python.ops.variable_scope) is deprecated and will be removed in a future version.
Instructions for updating
non-resource variables are not supported in the long term
2021-11-05 13:44:09.547652: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library ‘nvcuda.dll’; dlerror: nvcuda.dll not found
2021-11-05 13:44:09.548111: W tensorflow/stream_executor/cuda/cuda_driver.cc:269] failed call to cuInit: UNKNOWN ERROR (303)
2021-11-05 13:44:09.552603: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:169] retrieving CUDA diagnostic information for host: DESKTOP-F6P25NL
2021-11-05 13:44:09.552918: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:176] hostname: DESKTOP-F6P25NL
2021-11-05 13:44:09.553501: 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: AVX AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
4.0
Process finished with exit code 0
这没关系。它只是意味着您的 TensorFlow 未能充分利用您机器的潜力。例如,它无法使用您的 GPU 进行加速。
我购买了您的电子书《Python 深度学习》。在第 12 页的第 2.5 节“更多 Theano 资源”中,您提到了链接 http:// deeplearning .net,但该链接已失效。请告知是否有新的链接可用。谢谢。
你好 Alice…请看以下内容
https://anaconda.org/anaconda/theano
谢谢,詹姆斯。
非常欢迎你,Alice!
嘿,感谢您的帮助。
我运行了以下代码并看到了结果。
# TensorFlow 库示例
import tensorflow as tf
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
# 声明两个符号浮点标量
a = tf.placeholder(tf.float32)
b = tf.placeholder(tf.float32)
# 使用 add 函数创建一个简单的符号表达式
add = tf.add(a, b)
# 将 1.5 绑定到 'a',将 2.5 绑定到 'b',并评估 'c'
sess = tf.Session()
binding = {a: 1.5, b: 2.5}
c = sess.run(add, feed_dict=binding)
print(c)
当我们运行上面的代码片段时,我们将得到输出 4.0,这是给定变量值(a 和 b)的总和。
很好。
你好
Introduction too tensorflow.
# TensorFlow 库示例
import tensorflow as tf
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
# 声明两个符号浮点标量
a = tf.placeholder(tf.float32)
b = tf.placeholder(tf.float32)
# 使用 add 函数创建一个简单的符号表达式
add = tf.add(a, b)
# 将 1.5 绑定到 'a',将 2.5 绑定到 'b',并评估 'c'
sess = tf.Session()
binding = {a: 1.5, b: 2.5}
c = sess.run(add, feed_dict=binding)
print(c)
当我们运行上面的代码片段时,我们将得到输出 4.0,这是给定变量值(a 和 b)的总和。
很好。
感谢您的反馈,Sefineh!继续努力!
我尝试了 Lesson 1。运行代码后收到错误
AttributeError: module ‘numpy.distutils.__config__’ has no attribute ‘blas_opt_info’
抱歉,我是新手。
我尝试了 Lesson 2。结果如下
WARNING:tensorflow:From C:\Users\BHOGAYATA\DeepLearningenv\lib\site-packages\tensorflow\python\compat\v2_compat.py:107: disable_resource_variables (from tensorflow.python.ops.variable_scope) is deprecated and will be removed in a future version.
Instructions for updating
non-resource variables are not supported in the long term
4.0
accuracy: 76.82%
Lesson 06 : The findings
[0.72727273 0.74025974 0.75324675 0.75324675 0.67532468 0.5974026
0.74025974 0.63636364 0.73684211 0.77631579]
0.7136534518113465
我在深度学习的虚拟环境文件夹中保存了一个 weights-best 和 12 个 weights-improvement HDF5 文件。
Lesson 09: Dropouts (0.2) 之前的准确率和之后的准确率(基于 Pima Indians 糖尿病数据集):分别为 75.39% 和 73.18%。
Lesson 10
在我的例子中,使用 SGD,在 epochs=150、learning rate=0.1 和 momentum=0.8 的情况下,性能(以准确率衡量)从 75.39% 下降到 65.10%。
你好,
我们应该导入 tensorflow,其中
import tensorflow as tf
那么这些行的意思是?
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
运行代码得到了 4.0 的结果,但无法理解上面的行。
你好 Sumanata……以下资源可能对您感兴趣
https://docs.w3cub.com/tensorflow~2.3/compat/v1/disable_v2_behavior
从 https://storage.googleapis.com/tensorflow/tf-keras-datasets/mnist.npz 下载数据
11490434/11490434 [==============================] – 2s 0us/step
> 98.675
> 98.775
> 98.583
> 98.825
> 98.675
准确率:均值=98.707,标准差=0.085,n=5
损失 准确率
训练 0.9935 0.6550
验证 1.0250 0.6373
第13课的输出
亲爱的 Jason,
首先,我想感谢您提供在线课程。
我有一个问题,我构建了一个模型,基于第06课:将Keras模型与Scikit-Learn一起使用。我使用KerasClassifiers得到了0.7123547505126452的准确率。而在第05课中,我得到
第 150 周期/150
768/768 [==============================] – 0s 112us/sample – loss: 0.4945 – acc: 0.7721
准确率:76.95%
这两个准确率有什么区别?为什么?
不客气,Thinzar!对同一模型的多次运行结果在准确率上存在细微差异是正常的。以下资源解释了这一概念
https://machinelearning.org.cn/stochastic-in-machine-learning/
谢谢您,先生!我们应该取多次运行的平均准确率吗?模型训练中的偏差或过拟合又如何呢?
第一课:4
第二课
4
你好,
我对第一课和第二课有一些疑问。
变量a和b是如何被赋值的?
变量a的值是如何确定的?
a=1.5
b=2.5
?
为什么我们不直接相加这两个变量,而是使用第一课和第二课中使用的复杂代码呢?
a=1.5
b=2.5
print(a+b)
非常感谢您的帮助和赞赏
你好Najla…请看以下内容
https://towardsai.net/p/l/what-is-tensorflow-and-how-does-it-work
你好,
第一课答案:Theano
4.0
感谢您的反馈,Zaibunnisa!继续保持出色的工作!
我遇到了这些错误以及一个“bing”解释:错误消息表明没有可用的C++编译器,这是Theano 0.11及更高版本所必需的。警告消息建议Theano将默认使用Python实现,这将严重降低性能。要消除此警告,您可以将Theano标志cxx设置为空字符串1。
错误消息还表明配置文件中没有名为“blas”的部分2。这可能是由于必需库的安装缺失或不正确造成的。
要解决此问题,您可以尝试使用conda3安装m2w64-toolchain包。如果不行,您可以尝试安装C++编译器,例如MinGW GCC/G++1。您还可以检查必需的库是否安装正确,以及配置文件是否设置正确2。
请注意,错误消息很长且复杂,因此寻求社区论坛或技术专家的额外支持可能会有所帮助。
警告 (theano.configdefaults): g++ 不可用,如果使用 conda: `conda install m2w64-toolchain`
C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\configdefaults.py:560: UserWarning: DeprecationWarning: there is no c++ compiler.This is deprecated and with Theano 0.11 a c++ compiler will be mandatory
warnings.warn("DeprecationWarning: 没有 c++ 编译器。"
WARNING (theano.configdefaults): g++ not detected ! Theano will be unable to execute optimized C-implementations (for both CPU and GPU) and will default to Python implementations. Performance will be severely degraded. To remove this warning, set Theano flags cxx to an empty string.
回溯(最近一次调用)
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\configparser.py”, line 168, in fetch_val_for_key
return theano_cfg.get(section, option)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1776.0_x64__qbz5n2kfra8p0\Lib\configparser.py”, line 797, in get
d = self._unify_values(section, vars)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1776.0_x64__qbz5n2kfra8p0\Lib\configparser.py”, line 1168, in _unify_values
raise NoSectionError(section) from None
configparser.NoSectionError: No section: ‘blas’
处理上述异常时,发生了另一个异常
回溯(最近一次调用)
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\configparser.py”, line 327, in __get__
val_str = fetch_val_for_key(self.fullname,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\configparser.py”, line 172, in fetch_val_for_key
raise KeyError(key)
KeyError: ‘blas.ldflags’
处理上述异常时,发生了另一个异常
回溯(最近一次调用)
File “”, line 1, in
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\__init__.py”, line 124, in
from theano.scan_module import (scan, map, reduce, foldl, foldr, clone,
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\scan_module\__init__.py”, line 41, in
from theano.scan_module import scan_opt
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\scan_module\scan_opt.py”, line 60, in
from theano import tensor, scalar
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\tensor\__init__.py”, line 17, in
from theano.tensor import blas
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\tensor\blas.py”, line 155, in
from theano.tensor.blas_headers import blas_header_text
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\tensor\blas_headers.py”, line 987, in
if not config.blas.ldflags
^^^^^^^^^^^^^^^^^^^
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\configparser.py”, line 332, in __get__
val_str = self.default()
^^^^^^^^^^^^^^
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\configdefaults.py”, line 1284, in default_blas_ldflags
blas_info = np.distutils.__config__.blas_opt_info
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module ‘numpy.distutils.__config__’ has no attribute ‘blas_opt_info’
>>> from theano import tensor
回溯(最近一次调用)
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\configparser.py”, line 168, in fetch_val_for_key
return theano_cfg.get(section, option)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1776.0_x64__qbz5n2kfra8p0\Lib\configparser.py”, line 797, in get
d = self._unify_values(section, vars)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1776.0_x64__qbz5n2kfra8p0\Lib\configparser.py”, line 1168, in _unify_values
raise NoSectionError(section) from None
configparser.NoSectionError: No section: ‘blas’
处理上述异常时,发生了另一个异常
回溯(最近一次调用)
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\configparser.py”, line 327, in __get__
val_str = fetch_val_for_key(self.fullname,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\configparser.py”, line 172, in fetch_val_for_key
raise KeyError(key)
KeyError: ‘blas.ldflags’
处理上述异常时,发生了另一个异常
回溯(最近一次调用)
File “”, line 1, in
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\__init__.py”, line 124, in
from theano.scan_module import (scan, map, reduce, foldl, foldr, clone,
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\scan_module\__init__.py”, line 41, in
from theano.scan_module import scan_opt
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\scan_module\scan_opt.py”, line 60, in
from theano import tensor, scalar
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\tensor\__init__.py”, line 17, in
from theano.tensor import blas
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\tensor\blas.py”, line 155, in
from theano.tensor.blas_headers import blas_header_text
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\tensor\blas_headers.py”, line 987, in
if not config.blas.ldflags
^^^^^^^^^^^^^^^^^^^
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\configparser.py”, line 332, in __get__
val_str = self.default()
^^^^^^^^^^^^^^
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\configdefaults.py”, line 1284, in default_blas_ldflags
blas_info = np.distutils.__config__.blas_opt_info
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module ‘numpy.distutils.__config__’ has no attribute ‘blas_opt_info’
>>> from theano import tensor
回溯(最近一次调用)
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\configparser.py”, line 168, in fetch_val_for_key
return theano_cfg.get(section, option)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1776.0_x64__qbz5n2kfra8p0\Lib\configparser.py”, line 797, in get
d = self._unify_values(section, vars)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1776.0_x64__qbz5n2kfra8p0\Lib\configparser.py”, line 1168, in _unify_values
raise NoSectionError(section) from None
configparser.NoSectionError: No section: ‘blas’
处理上述异常时,发生了另一个异常
回溯(最近一次调用)
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\configparser.py”, line 327, in __get__
val_str = fetch_val_for_key(self.fullname,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\configparser.py”, line 172, in fetch_val_for_key
raise KeyError(key)
KeyError: ‘blas.ldflags’
处理上述异常时,发生了另一个异常
回溯(最近一次调用)
File “”, line 1, in
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\__init__.py”, line 124, in
from theano.scan_module import (scan, map, reduce, foldl, foldr, clone,
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\scan_module\__init__.py”, line 41, in
from theano.scan_module import scan_opt
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\scan_module\scan_opt.py”, line 60, in
from theano import tensor, scalar
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\tensor\__init__.py”, line 17, in
from theano.tensor import blas
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\tensor\blas.py”, line 155, in
from theano.tensor.blas_headers import blas_header_text
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\tensor\blas_headers.py”, line 987, in
if not config.blas.ldflags
^^^^^^^^^^^^^^^^^^^
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\configparser.py”, line 332, in __get__
val_str = self.default()
^^^^^^^^^^^^^^
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\configdefaults.py”, line 1284, in default_blas_ldflags
blas_info = np.distutils.__config__.blas_opt_info
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module ‘numpy.distutils.__config__’ has no attribute ‘blas_opt_info’
>>>
我遇到了这些错误以及一个“bing”解释:错误消息表明没有可用的C++编译器,这是Theano 0.11及更高版本所必需的。警告消息建议Theano将默认使用Python实现,这将严重降低性能。要消除此警告,您可以将Theano标志cxx设置为空字符串1。
错误消息还表明配置文件中没有名为“blas”的部分2。这可能是由于必需库的安装缺失或不正确造成的。
要解决此问题,您可以尝试使用conda3安装m2w64-toolchain包。如果不行,您可以尝试安装C++编译器,例如MinGW GCC/G++1。您还可以检查必需的库是否安装正确,以及配置文件是否设置正确2。
请注意,错误消息很长且复杂,因此寻求社区论坛或技术专家的额外支持可能会有所帮助。
警告 (theano.configdefaults): g++ 不可用,如果使用 conda: `conda install m2w64-toolchain`
C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\configdefaults.py:560: UserWarning: DeprecationWarning: there is no c++ compiler.This is deprecated and with Theano 0.11 a c++ compiler will be mandatory
warnings.warn("DeprecationWarning: 没有 c++ 编译器。"
WARNING (theano.configdefaults): g++ not detected ! Theano will be unable to execute optimized C-implementations (for both CPU and GPU) and will default to Python implementations. Performance will be severely degraded. To remove this warning, set Theano flags cxx to an empty string.
回溯(最近一次调用)
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\configparser.py”, line 168, in fetch_val_for_key
return theano_cfg.get(section, option)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1776.0_x64__qbz5n2kfra8p0\Lib\configparser.py”, line 797, in get
d = self._unify_values(section, vars)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1776.0_x64__qbz5n2kfra8p0\Lib\configparser.py”, line 1168, in _unify_values
raise NoSectionError(section) from None
configparser.NoSectionError: No section: ‘blas’
处理上述异常时,发生了另一个异常
回溯(最近一次调用)
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\configparser.py”, line 327, in __get__
val_str = fetch_val_for_key(self.fullname,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\configparser.py”, line 172, in fetch_val_for_key
raise KeyError(key)
KeyError: ‘blas.ldflags’
处理上述异常时,发生了另一个异常
回溯(最近一次调用)
File “”, line 1, in
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\__init__.py”, line 124, in
from theano.scan_module import (scan, map, reduce, foldl, foldr, clone,
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\scan_module\__init__.py”, line 41, in
from theano.scan_module import scan_opt
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\scan_module\scan_opt.py”, line 60, in
from theano import tensor, scalar
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\tensor\__init__.py”, line 17, in
from theano.tensor import blas
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\tensor\blas.py”, line 155, in
from theano.tensor.blas_headers import blas_header_text
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\tensor\blas_headers.py”, line 987, in
if not config.blas.ldflags
^^^^^^^^^^^^^^^^^^^
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\configparser.py”, line 332, in __get__
val_str = self.default()
^^^^^^^^^^^^^^
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\configdefaults.py”, line 1284, in default_blas_ldflags
blas_info = np.distutils.__config__.blas_opt_info
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module ‘numpy.distutils.__config__’ has no attribute ‘blas_opt_info’
>>> from theano import tensor
回溯(最近一次调用)
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\configparser.py”, line 168, in fetch_val_for_key
return theano_cfg.get(section, option)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1776.0_x64__qbz5n2kfra8p0\Lib\configparser.py”, line 797, in get
d = self._unify_values(section, vars)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1776.0_x64__qbz5n2kfra8p0\Lib\configparser.py”, line 1168, in _unify_values
raise NoSectionError(section) from None
configparser.NoSectionError: No section: ‘blas’
处理上述异常时,发生了另一个异常
回溯(最近一次调用)
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\configparser.py”, line 327, in __get__
val_str = fetch_val_for_key(self.fullname,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\configparser.py”, line 172, in fetch_val_for_key
raise KeyError(key)
KeyError: ‘blas.ldflags’
处理上述异常时,发生了另一个异常
回溯(最近一次调用)
File “”, line 1, in
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\__init__.py”, line 124, in
from theano.scan_module import (scan, map, reduce, foldl, foldr, clone,
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\scan_module\__init__.py”, line 41, in
from theano.scan_module import scan_opt
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\scan_module\scan_opt.py”, line 60, in
from theano import tensor, scalar
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\tensor\__init__.py”, line 17, in
from theano.tensor import blas
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\tensor\blas.py”, line 155, in
from theano.tensor.blas_headers import blas_header_text
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\tensor\blas_headers.py”, line 987, in
if not config.blas.ldflags
^^^^^^^^^^^^^^^^^^^
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\configparser.py”, line 332, in __get__
val_str = self.default()
^^^^^^^^^^^^^^
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\configdefaults.py”, line 1284, in default_blas_ldflags
blas_info = np.distutils.__config__.blas_opt_info
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module ‘numpy.distutils.__config__’ has no attribute ‘blas_opt_info’
>>> from theano import tensor
回溯(最近一次调用)
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\configparser.py”, line 168, in fetch_val_for_key
return theano_cfg.get(section, option)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1776.0_x64__qbz5n2kfra8p0\Lib\configparser.py”, line 797, in get
d = self._unify_values(section, vars)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1776.0_x64__qbz5n2kfra8p0\Lib\configparser.py”, line 1168, in _unify_values
raise NoSectionError(section) from None
configparser.NoSectionError: No section: ‘blas’
处理上述异常时,发生了另一个异常
回溯(最近一次调用)
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\configparser.py”, line 327, in __get__
val_str = fetch_val_for_key(self.fullname,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\configparser.py”, line 172, in fetch_val_for_key
raise KeyError(key)
KeyError: ‘blas.ldflags’
处理上述异常时,发生了另一个异常
回溯(最近一次调用)
File “”, line 1, in
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\__init__.py”, line 124, in
from theano.scan_module import (scan, map, reduce, foldl, foldr, clone,
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\scan_module\__init__.py”, line 41, in
from theano.scan_module import scan_opt
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\scan_module\scan_opt.py”, line 60, in
from theano import tensor, scalar
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\tensor\__init__.py”, line 17, in
from theano.tensor import blas
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\tensor\blas.py”, line 155, in
from theano.tensor.blas_headers import blas_header_text
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\tensor\blas_headers.py”, line 987, in
if not config.blas.ldflags
^^^^^^^^^^^^^^^^^^^
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\configparser.py”, line 332, in __get__
val_str = self.default()
^^^^^^^^^^^^^^
File “C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\theano\configdefaults.py”, line 1284, in default_blas_ldflags
blas_info = np.distutils.__config__.blas_opt_info
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module ‘numpy.distutils.__config__’ has no attribute ‘blas_opt_info’
>>> C:\Users\court>pip3 install theano
Collecting theano
Downloading Theano-1.0.5.tar.gz (2.8 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.8/2.8 MB 8.6 MB/s eta 0:00:00
Preparing metadata (setup.py) … done
Requirement already satisfied: numpy>=1.9.1 in c:\users\court\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from theano) (1.23.5)
Requirement already satisfied: scipy>=0.14 in c:\users\court\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from theano) (1.11.2)
Requirement already satisfied: six>=1.9.0 in c:\users\court\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from theano) (1.16.0)
Building wheels for collected packages: theano
Building wheel for theano (setup.py) … done
Created wheel for theano: filename=Theano-1.0.5-py3-none-any.whl size=2668148 sha256=718e629f46561b5ec6f963799d509428159db7a0f8fe6f95f54bdecfd6fc1053
Stored in directory: c:\users\court\appdata\local\pip\cache\wheels\26\1f\2f\02d738022626461828148150c0354e712c4ad74f1a60f10933
Successfully built theano
Installing collected packages: theano
WARNING: The scripts theano-cache.exe and theano-nose.exe are installed in ‘C:\Users\court\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\Scripts’ which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use –no-warn-script-location.
Successfully installed theano-1.0.5
我在Google Colab中也遇到了这个“No section: ‘blas'”错误。
你好Bart…以下资源可能对您感兴趣
https://stackoverflow.com/questions/48673863/anaconda-theano-installation-error
“No section: ‘blas'”错误消息通常出现在Python环境中,并且与配置设置有关,特别是在使用依赖BLAS(Basic Linear Algebra Subprograms)进行数值计算的库时。当程序尝试从文件(如
.ini
文件)读取BLAS的配置设置,但指定的节不存在时,通常会出现此错误。以下是纠正此错误的一些步骤:
1. **检查配置文件**:确保程序尝试读取的配置文件(通常是
.ini
文件)存在且格式正确。该文件应包含一个名为[blas]
的节。2. **安装所需库**:如果您的项目需要特定的BLAS库(如OpenBLAS、MKL或ATLAS),请确保它们已在您的环境中正确安装。
3. **环境变量**:一些Python库(如NumPy)使用环境变量来查找正确的BLAS实现。确保这些已正确设置。
4. **正确的库路径**:如果BLAS库已安装但未被找到,请确保在配置文件或环境变量中正确设置了路径。
5. **更新或重新安装依赖项**:有时,简单地更新或重新安装依赖于BLAS的Python库就可以解决问题。
6. **Python虚拟环境**:如果您正在使用虚拟环境,请确保环境设置正确,并且所有必需的包都已安装在其中。
7. **查阅文档**:查看您正在使用的库的文档。它可能包含有关设置BLAS或处理此类错误的具体说明。
8. **寻求社区帮助**:如果问题仍然存在,请考虑向您正在使用的库相关的社区或论坛寻求帮助。
如果您能提供更多关于错误发生背景的细节,例如您正在使用的Python库或您的配置文件内容,我可以提供更具针对性的建议。
# TensorFlow 库示例
import tensorflow as tf
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
# 声明两个符号浮点标量
a = tf.placeholder(tf.float32)
b = tf.placeholder(tf.float32)
# 使用 add 函数创建一个简单的符号表达式
add = tf.add(a, b)
# 将 1.5 绑定到 'a',将 2.5 绑定到 'b',并评估 'c'
sess = tf.Session()
binding = {a: 1.5, b: 2.5}
c = sess.run(add, feed_dict=binding)
print(c)
答案:4.0