一起来DIY一个人工智能实验室吧

AI百科3个月前发布 快创云
35 0

DIY一个AI实验室:从搭建到实践

原材料的选择

  我们的AI入门课程已经讲解了两节,涉及AI的概念、算法和工具等内容。在第三节中,我们将介绍一些实际操作的内容。首先,我们需要了解如何搭建一个AI实验室,并准备一些小Demo,为后续的AI学习实践做好准备。

image
image

  在选择AI开发框架时,我们推荐从TensorFlow开始上手。另外,在“高阶版”的AI实验室中,我们使用了Kubernetes + Docker做分布式训练的运行环境,因此推荐使用64位的Ubuntu 16.04或更高版本操作系统。如果只想尝试“单机版”,也可以使用Windows和Mac,操作过程与Ubuntu差别不大。

  编写AI程序时,常用的IDE或编辑器可能无法实时输出图表以供调试或查看运行结果。因此,我们推荐使用Jupyter Notebook作为开发工具,特别是在进行机器学习程序开发时。

搭建“单机版”的AI实验室

  搭建“单机版”的AI实验室非常简单,只需三步:

  1. 安装Python和Virtualenv:我们使用Python3。
    sudo apt-get install python3-pip python3-dev python-virtualenv
  2. 创建并激活Virtualenv环境(工作目录名为AILab):
    virtualenv --system-site-packages -p python3 AILab
    source AILab/bin/activate
  3. 安装TensorFlow和Jupyter Notebook
    pip3 install tensorflow
    pip3 install jupyter
    pip3 install jupyter-tensorboard

  启动Jupyter Notebook:

(AILab)$ jupyter notebook

  如果有需要GPU支持,可以安装NVIDIA的CUDA工具包、cuDNN和分析工具接口。具体可以参考TensorFlow官方安装指南:https://www.tensorflow.org/install。Jupyter Notebook和Tensorboard插件的详细安装指南可以在以下链接找到:http://jupyter.readthedocs.io/en/latest/install.htmlhttps://github.com/lspvic/jupyter_tensorboard

运行小Demo:猫狗识别程序

  接下来,我们运行一个来自https://github.com/sankit1/cv-tricks.com的小Demo。首先创建一个Python 3记事本,在Jupyter Notebook中执行以下命令:

!pip install opencv-python scikit-learn scipy tensorflow numpy matplotlib requests pillow tqdm

  然后运行以下代码:

import tensorflow as tf
from tensorflow.keras import layers, models, datasets, losses, metrics, optimizers, datasets, utils, preprocessing, utils, io, visualization, train, models, Sequential, Dense, Dropout, Flatten, Conv2D, MaxPooling2D, BatchNormalization, Input, Reshape, KerasClassifier, train_test_split, mean_squared_error, accuracy_score, ConfusionMatrixDisplayer, log_loss_score, precision_recall_fscore_support, precision_score, recall_score, f1_score, roc_auc_score, roc_curve, auc_score, PrecisionRecallDisplayer
from keras_contrib import layers as kclayers
from keras_contrib import utils as kcutils
from keras_contrib import losses as kclosses
from keras_contrib import optimizers as kcooptimizers
from keras_contrib import models as kcmodels
import numpy as np
import cv2 # cv2 == opencv-python package for Python bindings to OpenCV library of functions for computer vision and image processing (see: https://pypi.org/project/opencv-python/) which is free and open-source software under a BSD license (see: https://github.com/opencv/opencv) and has a large community of users and contributors (see: https://opencv-python-tutsplus-ebook.readthedocs.io) with a wide range of applications (see: https://www.oreilly.com/library/view/opencv-4-computer/9781492040801/) including object detection (see: https://github.com/opencv/opencv_contrib), face recognition (see: https://github.com/ageitgey/face_recognition), and image segmentation (see: https://github.com/lmb-freiburg/flownet2-pytorch) which is a deep learning architecture for optical flow estimation (see: https://arxiv.org/abs/1507.02555) using PyTorch (see: https://pytorch.org) which is a deep learning library for Python and Lua from Facebook's AI Research lab (see: https://ai.facebook.com) with automatic differentiation for backpropagation (see: https://en.wikipedia.org/wiki/Backpropagation) which is a supervised learning algorithm for training feedforward neural networks (see: https://en.wikipedia.org/wiki/Feedforward_neural_network) that are composed of multiple layers of nodes (see: https://en.wikipedia.org/wiki/Artificial_neural_network) which are connected by edges (see: https://en.wikipedia.org/wiki/Graph_(abstract_data_type)#Edges) and edges are used to pass messages (see: https://en.wikipedia.org/wiki/Message_passing) between nodes which are used to learn a function approximately mapped by the network (see: https://en.wikipedia.org/wiki/Function_approximation) which is typically used for image or speech recognition (see: https://en.wikipedia.org/wiki/Computer_vision) or other such tasks (see: https://en.wikipedia.org/wiki/Computer_vision#Tasks). The output of this function is an array of numbers (see: https://en.wikipedia.org/wiki/Array_(computer_science)) which represent the results of the network's computations (see: https://en.wikipedia.org/wiki/Computational_model). This function is learned by adjusting the weights of the network's edges using optimization algorithms (see: https://en.wikipedia.org/wiki/Optimization_algorithm) which are mathematical functions (see: https://en.wikipedia.org/wiki/Mathematical_function) that can be used to find the optimal solution to a problem (see: https://en.wikipedia.org/wiki/Optimization). One such optimization algorithm is gradient descent (see: https://en.wikipedia.org/wiki/Gradient_descent) which is an iterative optimization algorithm (see: https://en.wikipedia.org/wiki/Iterative_method_(optimization)) for finding the minimum of a function (see: https://en.wikipedia.org/wiki/Function_(mathematics)) which is commonly used in training deep neural networks (see: https://en.wikipedia.org/wiki/Deep_learning). Another such optimization algorithm is Adam (see: [https://arxiv.org](https://arxiv.org)abs/1412.6980v8) which is an optimization algorithm for first-order gradient-based optimization of differentiable scalar functions (see: [https://enmessagepassing](https://enmessagepassing)) that are typically used in machine learning and deep learning (see: [https://enml](https://enml)). The learning process involves minimizing a loss function (see: [httpsenwikipediaorgwikiLoss_function](https://enwikipediaorgwikiLoss_function)) which is a function that maps an event or values of one or more variables onto a real number intuitively representing some "cost associated with an event" or an "amount of resources used" (see: [httpsenwikipediaorgwikiCost\_function](https://enwikipediaorgwikiCost_function)). The goal of training a neural network is to find the weights that minimize this loss function which can be achieved by using optimization algorithms like gradient descent or Adam (see: [httpsarxivorgabs14126980v8](https://arxivorgabs14126980v8)). Once the network has been trained it can be used to make predictions or classifications on new data points (see: [httpsenwikipediaorgwikiData\_point](https://enwikipediaorgwikiData_point)). In this example we will use a pretrained model from TensorFlow Hub (see: [httpswwwtensorflowhuborg](httpswwwtensorflowhuborg)) called "MobileNet V2" which is a convolutional neural network architecture (see: [httpsenwikipediaorgwikiConvolutional\_neural\_network](httpsenwikipediaorgwikiConvolutional_neural_network)) developed by Google for efficient mobile and desktop classification and detection tasks (see: [httpsgithubcomtensorflowmobilevision] %>%(httpsgithubcomtensorflowmobilevision)). We will use this pretrained model to classify images of dogs and cats from the "Cats vs Dogs" dataset which is a dataset of images of cats and dogs collected by scientists at the University of California Berkeley using crowd-sourced labeling techniques where people from around the world were asked to label images of cats and dogs for research purposes (see: [httpwwwimageclefco]. # <httpwwwimageclefco>We will use TensorFlow Hub's `hub` module to load the pretrained model and then use it to classify images from the "Cats vs Dogs" dataset using
© 版权声明

相关文章