卷积神经网络中神经元的定义_自动创建性能最佳的神经网络而无需定义体系结构

卷积神经网络中神经元的定义

Automated Machine Learning, commonly abbreviated as AutoML, is the automation of the building of neural network structures. Through intelligent architecture manipulations, AutoML can not only make deep learning more accessible for everyone but accelerate deep learning research.

自动化机器学习,通常缩写为AutoML,是神经网络结构构建的自动化。 通过智能架构操纵,AutoML不仅可以使每个人都可以更深入地学习深度学习,而且可以加速深度学习研究。

In this article, we’ll go over:

在本文中,我们将介绍:

  • How to install AutoKeras for neural architecture searches.

    如何安装AutoKeras进行神经体系结构搜索。
  • How to use AutoKeras to find the best neural architectures using structured, image, and text data for regression and classification tasks.

    如何使用AutoKeras使用结构化,图像和文本数据查找最佳神经结构,以进行回归和分类任务。
  • How to evaluate, predict, export to Keras/TensorFlow, and view architecture of obtained high-performing models.

    如何评估,预测,导出到Keras / TensorFlow以及查看获得的高性能模型的体系结构。

一窥AutoKeras (A Glimpse into AutoKeras)

  • With AutoKeras, a neural architecture search algorithm finds the best architectures, like the number of neurons in a layer, the number of layers, which layers to incorporate, layer-specific parameters like filter size or percent of dropped neurons in Dropout, etc. Once the search is complete, you can use the model as a normal TensorFlow/Keras model.

    使用AutoKeras,神经体系结构搜索算法可以找到最佳的体系结构,例如层中神经元的数量,层数,要合并的层,特定于层的参数(例如过滤器大小或Dropout中丢弃的神经元的百分比等)。搜索完成后,您可以将该模型用作普通的TensorFlow / Keras模型。
  • By using AutoKeras, you can build a model with complex elements like embeddings and spatial reductions that would otherwise be less accessible to those who are still in the process of learning DL.

    通过使用AutoKeras,您可以使用包含嵌入和空间缩小等复杂元素的模型来构建模型,否则这些元素对于仍在学习DL的人们来说将是较难获得的。
  • When AutoKeras creates models for you, much of preprocessing, like vectorizing or cleaning text data, is done and optimized for you.

    当AutoKeras为您创建模型时,将为您完成并优化许多预处理,例如矢量化或清除文本数据。
  • It takes two lines to initiate and train a search. AutoKeras boasts a Keras-like interface, so it’s not hard to remember and use at all.

    需要两行来启动和训练搜索。 AutoKeras具有类似Keras的界面,因此一点也不难记住和使用。

Excited yet? Let’s get started!

激动了吗? 让我们开始吧!

安装 (Installation)

Before you install, ensure you have the following prerequisites:

在安装之前,请确保您具有以下先决条件:

In your command line, run two commands. This should properly install AutoKeras. Note that these installations, unfortunately, do not work in Kaggle notebooks, so it’s best to run these on a local environment.

在您的命令行中,运行两个命令。 这应该正确安装AutoKeras。 请注意,不幸的是,这些安装不适用于Kaggle笔记本电脑,因此最好在本地环境中运行它们。

As a test, run import autokeras in your coding environment to ensure everything is working.

作为测试, import autokeras在您的编码环境中运行import autokeras以确保一切正常。

结构化数据分类/回归任务 (Structured Data Classification/Regression Tasks)

Let’s use the famous iris dataset, which we can import from sklearn’s several handy toy datasets. The result (data) of a data import is a dictionary with two keys, ‘data’ and ‘target’.

让我们使用著名的虹膜数据集,我们可以从sklearn的几个方便的玩具数据集中导入。 数据导入的结果( data )是带有两个键的字典,即“ data ”和“ target ”。

However, since the target is categorical (three values), we’ll need to dummy-encode it. Since the result is a pandas DataFrame and a NumPy array is desired, we call .values after pd.get_dummies (which one-hot encodes).

但是,由于目标是分类的(三个值),因此我们需要对其进行虚拟编码。 由于结果是pandas DataFrame,并且需要NumPy数组,因此我们在pd.get_dummies (一键编码)之后调用.values

Calling X.shape yields (150, 4) and calling y.shape yields (150, 3). This makes sense — there are 150 rows, 4 columns in X, and 3 unique categories in y (hence three columns). In order to evaluate our model, we will split the data into training and testing sets.

调用X.shape产量( X.shape )和调用y.shape产量( y.shape )。 这是有道理的X有150行, X有4列, y 3个唯一的类别(因此有3列)。 为了评估我们的模型,我们将数据分为训练和测试集。

It’s always good practice to check the shape of arrays:

始终最好检查数组的形状:

  • X_train: (105, 4)

    X_train :( X_train )

  • X_test: (45, 4)

    X_test :( X_test )

  • y_train: (105, 3)

    y_train :( y_train )

  • y_test: (45, 3)

    y_test :( y_test )

Great! — everything adds up. We can begin working with autokeras.

大! -一切加起来。 我们可以开始使用autokeras

Importing autokeras should be no problem. A StructuredDataClassifier is a search object that works on ‘structured data’, or standard two-dimensional data with columns and a label. The max_trials parameter indicates the maximum number of models to test; this can be set higher in the case of the iris dataset since it is so small. Often the search will end before max_trials is met (it serves as an upper bound).

导入autokeras应该没问题。 StructuredDataClassifier是一个搜索对象,用于处理“结构化数据”或带有列和标签的标准二维数据。 max_trials参数指示要测试的最大模型数。 由于虹膜数据集很小,因此可以将其设置得更高。 通常,搜索会在满足max_trials之前结束(它充当上限)。

For regression problems, use StructuredDataRegressor.

对于回归问题,请使用StructuredDataRegressor

We can initiate the search process by calling .fit(). verbose is a parameter that can be set to 0 or 1, depending on if you would like the model to output information about training, like the architecture of potential networks and epoch-by-epoch progress. However, there are hundreds of epochs for each potential architecture, so it may take up space and slow down training.

我们可以通过调用.fit()来启动搜索过程。 verbose是可以设置为0或1的参数,具体取决于您是否希望模型输出有关训练的信息,例如潜在网络的架构和逐时进度。 但是,每种潜在架构都有数百个时期,因此可能会占用空间并减慢训练速度。

It’s always worth setting verbose=1 at least once to peek into what is going on behind the scenes, since the entire search takes at least several minutes to complete. Take this sample output:

至少一次设置verbose = 1总是值得一看的,以了解幕后情况,因为整个搜索至少需要几分钟才能完成。 取得以下示例输出:

If you’re up to it, it’s fascinating to watch the architectures transform over time, and what elements are going into the final neural network.

如果您愿意的话,那么观看架构随时间的变化以及最终的神经网络中将包含哪些元素,将非常着迷。

On my local environment, it took ~1 hour in total with no GPU acceleration to run through 15 trials.

在我的本地环境中,总共花费了大约1个小时,并且没有GPU加速来运行15次试用。

Once your model has been fit, we can evaluate its performance or obtain predictions. Generally, this is a quick process so verbose can be set to 0.

拟合好模型后,我们可以评估其性能或获得预测。 通常,这是一个快速过程,因此可以将verbose设置为0。

To view more details about the model structure and to save it, we need to export it using model = search.export_model(). Here, model is a standard TensorFlow/Keras model, not a AutoKeras object.

要查看有关模型结构的更多详细信息并保存它,我们需要使用model = search.export_model()导出它。 在这里, model是标准的TensorFlow / Keras模型,而不是AutoKeras对象。

Calling model.summary() will print out best architecture obtained by the neural architecture search.

调用model.summary()将打印出通过神经体系结构搜索获得的最佳体系结构。

To save the weights, call model.save(‘filepath/weights.h5’).

要保存权重,请调用model.save('filepath/weights.h5')

图像分类/回归 (Image Classification/Regression)

Image classification and regression work much like classification and regression on standard structured data, but the neural network is built using elements of convolutional neural networks, like convolutional layers, max pooling, and flattening. All parameters are learned.

图像分类和回归的工作方式与对标准结构化数据的分类和回归非常相似,但是神经网络是使用卷积神经网络的元素(如卷积层,最大池和展平度)构建的。 学习所有参数。

For example, let’s work on the MNIST dataset to find a convolutional neural network to recognize digits from 28 by 28 images. Keras datasets provide a handy method to retrieve this data, but the y-variables need to be converted into dummy variables.

例如,让我们在MNIST数据集上工作,找到一个卷积神经网络,以识别28 x 28图像中的数字。 Keras数据集提供了一种方便的方法来检索此数据,但是y变量需要转换为虚拟变量。

Let’s check the shape of the data.

让我们检查数据的形状。

  • X_train: (60000, 28, 28)

    X_train :( X_train )

  • X_test: (10000, 28, 28)

    X_test :( X_test )

  • y_train: (60000, 10)

    y_train :( y_train )

  • y_test: (10000, 10)

    y_test :( y_test )

Great! AutoKeras can also handle four-dimensional data (colored images with multiple channels). We can create a search object with ImageClassifier (or, ImageRegressor for regression tasks):

大! AutoKeras还可以处理四维数据(具有多个通道的彩色图像)。 我们可以使用ImageClassifier (或用于回归任务的ImageRegressor )创建搜索对象:

*If you are running multiple searches, add a parameter overwrite=True when defining the search object (ak.object(overwrite=True, max_trials=x)). Otherwise, there will be an error.

*如果要运行多个搜索,请在定义搜索对象时添加参数overwrite = True( ak.object(overwrite=True, max_trials=x) )。 否则会出现错误。

Evaluation, prediction, and exporting are performed the same as with structured classifiers and regressors. Note that a neural architecture search with images will take a substantially longer period of time.

评估,预测和导出的执行方式与结构化分类器和回归器相同。 注意,使用图像进行神经体系结构搜索将花费相当长的时间。

文字分类/回归 (Text Classification/Regression)

AutoKeras doesn’t require any text vectorization, which is handy because there are so many ways to do so and each can be lengthy to implement. Instead, this is learned by the model.

AutoKeras不需要任何文本矢量化,这很方便,因为这样做的方法太多了,而且每种实现都可能很长。 相反,这是由模型学习的。

Let’s use the 20 News Groups dataset, which consists of several news excerpts belonging to 20 different categories. To save time and computing expenses, we’ll only choose to import four categories and have a rather large test-size split (half the dataset).

让我们使用20个新闻组数据集,其中包含属于20个不同类别的几个新闻摘录。 为了节省时间和计算费用,我们将只选择导入四个类别并进行相当大的测试规模拆分(将数据集减半)。

X_train and X_test each are arrays comprised of 1128 raw text strings, y_train and y_test are each arrays of shape (1128, 4).

X_trainX_test都是由1128个原始文本字符串组成的数组, y_trainy_test分别是形状( y_test的数组。

Note that AutoKeras can handle strings of variable lengths! Each string in the input does not need to be the same length.

请注意,AutoKeras可以处理可变长度的字符串! 输入中的每个字符串不必长度相同。

Next, let’s build our text classifier/regressor.

接下来,让我们构建文本分类器/回归器。

*If you are running multiple searches, add a parameter overwrite=True when defining the search object (ak.object(overwrite=True, max_trials=x)). Otherwise, there will be an error.

*如果要运行多个搜索,请在定义搜索对象时添加参数overwrite = True( ak.object(overwrite=True, max_trials=x) )。 否则会出现错误。

Evaluation, prediction, and exporting are performed the same as with structured classifiers and regressors.

评估,预测和导出的执行方式与结构化分类器和回归器相同。

It’s worth taking a look at the proposed networks. The fusion between NLP and Deep Learning can be extraordinary advanced, and it’s amazing that complex elements like embeddings, spatial reductions, etc. can be implemented without needing to be explicitly called.

值得一看建议的网络。 NLP和深度学习之间的融合可以是非常先进的,令人惊讶的是,无需嵌入即可实现诸如嵌入,空间缩小等复杂元素。

With AutoKeras, deep learning becomes more accessible for all!

借助AutoKeras,所有人都可以更轻松地进行深度学习!

If you’re interested in the theory behind neural architecture search, read this:

如果您对神经体系结构搜索背后的理论感兴趣,请阅读以下内容:

To explore more with AutoKeras, view the documentation.

要使用AutoKeras进行更多探索,请查看文档

Thanks for reading! 😄

谢谢阅读! 😄

翻译自: https://towardsdatascience.com/automl-creating-top-performing-neural-networks-without-defining-architectures-c7d3b08cddc

卷积神经网络中神经元的定义

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值