日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人工智能 > pytorch >内容正文

pytorch

深度学习(1)深度学习初见

發布時間:2023/12/15 pytorch 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 深度学习(1)深度学习初见 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

深度學習(1)深度學習初見

  • 深度學習框架介紹
    • 1. TensorFlow發展歷程
    • 2. TensorFlow eco-system
    • 3. 學習建議
    • 4. 為什么要使用TensorFlow

深度學習框架介紹

1. TensorFlow發展歷程

(1) 2015

  • Scikit-learn
    • Machine Learning,No GPU
  • Caffe
    • 2013,第一個面向深度學習的框架
    • No auto-grad,C++
  • Keras
  • wrapper
  • Theano
    • 開發難,調試難
  • Torch
    • Lua語言

(2) TensorFlow

  • Caffe
    • Facebook,Caffe →\to Torch
    • Torch →\to PyTorch
  • Theano
    • Google,→\to TensorFlow
    • TensorFlow →\to TensorFlow2
  • Chainer
  • MXNet

(3) 2017: TensorFlow1.0

  • tf.contrib
    • tf.layers,tf.metrics,tf.losses
  • tfdbg
  • PyTorch 0.1

(4) TensorFlow 1.X 缺點

  • 調試困難
  • API混亂
  • 入門困難,入了門依舊困難
  • 大批研究人員轉向PyTorch

(5) 2019

  • TensorFlow 2.0 發布
  • TF+Keras
  • 更容易使用
    去掉了一些概念,例如:
    session.run
    tf.comtrol_dependencies
    tf.global_variables_initializer
    tf.cond,tf.while_loop

2. TensorFlow eco-system

(1) TensorFlow 2.0
TensorFlow核心庫

  • @tf.function
    將動態圖的語言變為靜態圖,使計算加速。
    (2) TensorFlow Lite
    (3) TensorFlow.JS
    (4) TensorFlow Extended
    TensorFlow Lite、TensorFlow.JS、TensorFlow Extended構成了TensorFlow的生態系統,從這點上看,TensorFlow是領先于PyTorch的。
    (5) TensorFlow Prob
    (6) TPU Cloud
    Google自己研發的加速硬件。

3. 學習建議

(1) 忘掉TensorFlow 1.X
(2) PyTorch和TensorFlow選一主修(二者都要掌握)
(3) Keras逐漸淡出(已經被Google收購了)

  • TF+Keras
  • PyTorch+Caffe2

4. 為什么要使用TensorFlow

  • GPU加速
  • 自動求導
  • 神經網絡Layers
    (1) GPU加速
    GPU和CPU對比
import tensorflow as tf import timeitwith tf.device('/cpu:0'):cpu_a = tf.random.normal([10000, 1000])cpu_b = tf.random.normal([1000, 2000])print(cpu_a.device, cpu_b.device)with tf.device('/gpu:0'):gpu_a = tf.random.normal([10000, 1000])gpu_b = tf.random.normal([1000, 2000])print(gpu_a.device, gpu_b.device)def cpu_run():with tf.device('/cpu:0'):c = tf.matmul(cpu_a, cpu_b)return cdef gpu_run():with tf.device('/gpu:0'):c = tf.matmul(gpu_a, gpu_b)return c# warm up cpu_time = timeit.timeit(cpu_run, number=10) gpu_time = timeit.timeit(gpu_run, number=10) print('warmup:', cpu_time, gpu_time)cpu_time = timeit.timeit(cpu_run, number=10) gpu_time = timeit.timeit(gpu_run, number=10) print('run time:', cpu_time, gpu_time)

運行結果:

可以看到,使用GPU運行要比使用CPU運行快(正常是快很多,我用的MacBook運行的)。
(2) 自動求導
例子:
y=a2?x+b?x+cy=a^2*x+b*x+cy=a2?x+b?x+c
其中: x=1;a=2;b=3;c=4x=1;a=2;b=3;c=4x=1;a=2;b=3;c=4
代碼如下:

import tensorflow as tfx = tf.constant(1.) a = tf.constant(2.) b = tf.constant(3.) c = tf.constant(4.)with tf.GradientTape() as tape:tape.watch([a, b, c])y = a**2 * x + b * x + c[dy_da, dy_db, dy_dc] = tape.gradient(y, [a, b, c]) print(dy_da, dy_db, dy_dc)

運行結果:

(3) 神經網絡API

神經網絡API神經網絡API
tf.matmullayers.Dense
tf.nn.conv2dlayers.Conv2D
tf.nn.relulayers.SimpleRNN
tf.nn.max_pool2dlayers.LSTM
tf.nn.sigmoidlayers.ReLU
tf.nn.softmaxlayers.MAxPool2D

參考文獻:
[1] 龍良曲:《深度學習與TensorFlow2入門實戰》

總結

以上是生活随笔為你收集整理的深度学习(1)深度学习初见的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。