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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

CS231n Convolutional Neural Networks for Visual Recognition------Scipy and MatplotlibTutorial

發(fā)布時間:2023/12/10 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 CS231n Convolutional Neural Networks for Visual Recognition------Scipy and MatplotlibTutorial 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

源鏈接為:http://cs231n.github.io/python-numpy-tutorial/。

這篇指導(dǎo)書是由Justin Johnson編寫的。

在這門課程中我們將使用Python語言完成所有變成任務(wù)!Python本身就是一種很棒的通用編程語言,但是在一些流行的庫幫助下(numpy,scipy,matplotlib)它已經(jīng)成為科學(xué)計算的強大環(huán)境。
我們希望你們中的許多人都有一些Python和numpy的使用經(jīng)驗; 對你們其他人來說,這個section將作為Python用于科學(xué)計算和使用的快速速成課程。
你們中的一些人可能已經(jīng)掌握了Matlab的知識,在這種情況下我們也推薦使用numpy。

你也可以閱讀由Volodymyr Kuleshov和Isaac Caswell(CS 228)編寫的Notebook版筆記。

本教程使用的Python版本為Python3.


目錄

Scipy

Image operations

MATLAB files

Distance between points

Matplotlib

Plotting

Subplots

Images


原文共分為4部分,分別介紹了Python、Numpy、Scipy和Matplotlib的使用。本次翻譯為最后兩個部分:Scipy和Matplotlib的使用指導(dǎo)!

Scipy

Numpy提供了一個高性能的多維數(shù)組以及計算和操作這些數(shù)組的基本工具。Scipy(官方鏈接)以此為基礎(chǔ),提供大量在numpy數(shù)組上運行的函數(shù),適用于不同類型的科學(xué)和工程應(yīng)用。熟悉Scipy最好的方法就是瀏覽官方文檔。我們將重點介紹一些對你可能有用的部分。

Image operations

Scipy提供了一些處理圖像的基本函數(shù)。例如,它有將圖像從磁盤讀取到numpy數(shù)組,將numpy數(shù)組作為圖像寫入磁盤以及調(diào)整圖像大小的功能。 這是一個展示這些功能的簡單示例:

from scipy.misc import imread, imsave, imresize# Read an JPEG image into a numpy array img = imread('assets/cat.jpg') print(img.dtype, img.shape) # Prints "uint8 (400, 248, 3)"# We can tint the image by scaling each of the color channels # by a different scalar constant. The image has shape (400, 248, 3); # we multiply it by the array [1, 0.95, 0.9] of shape (3,); # numpy broadcasting means that this leaves the red channel unchanged, # and multiplies the green and blue channels by 0.95 and 0.9 # respectively. img_tinted = img * [1, 0.95, 0.9]# Resize the tinted image to be 300 by 300 pixels. img_tinted = imresize(img_tinted, (300, 300))# Write the tinted image back to disk imsave('assets/cat_tinted.jpg', img_tinted)

???

Left: The original image. Right: The tinted and resized image.


MATLAB files

scipy.io.loadmatscipy.io.savemat函數(shù)允許你讀取和寫入MATLAB文件。你可以看這篇文檔了解更多。

Distance between points

SciPy定義了一些用于計算各組點之間距離的有用函數(shù)。

函數(shù)scipy.spatial.distance.pdist計算給定集合中所有點對之間的距離:

import numpy as np from scipy.spatial.distance import pdist, squareform# Create the following array where each row is a point in 2D space: # [[0 1] # [1 0] # [2 0]] x = np.array([[0, 1], [1, 0], [2, 0]]) print(x)# Compute the Euclidean distance between all rows of x. # d[i, j] is the Euclidean distance between x[i, :] and x[j, :], # and d is the following array: # [[ 0. 1.41421356 2.23606798] # [ 1.41421356 0. 1. ] # [ 2.23606798 1. 0. ]] d = squareform(pdist(x, 'euclidean')) print(d)

你可以在這篇文檔里了解更多細(xì)節(jié)。另一個相似函數(shù)(scipy.spatial.distance.cdist)計算兩組點之間所有對之間的距離; 你可以在文檔中閱讀它。

Matplotlib

Matplotlib是一個畫圖函數(shù),這部分主要介紹matplotlib.pyplot模塊,作用和MATLAB里的畫圖系統(tǒng)相似。

Plotting

在matplotlib里最重要的函數(shù)時plot,使用它可以繪制2D數(shù)據(jù),這里有一個簡單例子:

import numpy as np import matplotlib.pyplot as plt# Compute the x and y coordinates for points on a sine curve x = np.arange(0, 3 * np.pi, 0.1) y = np.sin(x)# Plot the points using matplotlib plt.plot(x, y) plt.show() # You must call plt.show() to make graphics appear.


只需一點額外工作,我們就可以輕松地一次繪制多條線,并添加標(biāo)題,圖例和軸標(biāo)簽:

import numpy as np import matplotlib.pyplot as plt# Compute the x and y coordinates for points on sine and cosine curves x = np.arange(0, 3 * np.pi, 0.1) y_sin = np.sin(x) y_cos = np.cos(x)# Plot the points using matplotlib plt.plot(x, y_sin) plt.plot(x, y_cos) plt.xlabel('x axis label') plt.ylabel('y axis label') plt.title('Sine and Cosine') plt.legend(['Sine', 'Cosine']) plt.show()


你可以在這篇文檔里了解更多關(guān)于plot的信息。

Subplots

您可以使用子圖功能在同一圖中繪制不同的東西。 這是一個例子:

import numpy as np import matplotlib.pyplot as plt# Compute the x and y coordinates for points on sine and cosine curves x = np.arange(0, 3 * np.pi, 0.1) y_sin = np.sin(x) y_cos = np.cos(x)# Set up a subplot grid that has height 2 and width 1, # and set the first such subplot as active. plt.subplot(2, 1, 1)# Make the first plot plt.plot(x, y_sin) plt.title('Sine')# Set the second subplot as active, and make the second plot. plt.subplot(2, 1, 2) plt.plot(x, y_cos) plt.title('Cosine')# Show the figure. plt.show()


你可以在這篇文檔里了解更多關(guān)于subplot的信息。

Images

你可以使用imshow函數(shù)來顯示圖片,這里有一個例子:

import numpy as np from scipy.misc import imread, imresize import matplotlib.pyplot as pltimg = imread('assets/cat.jpg') img_tinted = img * [1, 0.95, 0.9]# Show the original image plt.subplot(1, 2, 1) plt.imshow(img)# Show the tinted image plt.subplot(1, 2, 2)# A slight gotcha with imshow is that it might give strange results # if presented with data that is not uint8. To work around this, we # explicitly cast the image to uint8 before displaying it. plt.imshow(np.uint8(img_tinted)) plt.show()

?

總結(jié)

以上是生活随笔為你收集整理的CS231n Convolutional Neural Networks for Visual Recognition------Scipy and MatplotlibTutorial的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。