嘗試ChatGPT搞CV開發(fā)
在短短的兩個星期內(nèi),ChatGPT 迅速成為公眾聊天的焦點。超過一百萬的人與OpenAI的新聊天機器人“交談”,讓它寫詩和大學(xué)論文,生成創(chuàng)意食譜,創(chuàng)建虛擬機…它也被用來撰寫新聞文章和YouTube視頻的介紹。
作為計算機視覺公司的機器學(xué)習(xí)工程師,我在過去的幾天里一直嘗試了解 ChatGPT 對 CV 了解的極限。我想知道這種語言模型對該領(lǐng)域的未來(和現(xiàn)在)意味著什么。
該帖子分為 5 個部分:
什么是ChatGPT?
ChatGPT擅長的地方
面臨的挑戰(zhàn)
在哪些方面需要極度謹(jǐn)慎
為什么可以為 ChatGPT 授予CV工程師
什么是ChatGPT?
ChatGPT 于2022年11月30日發(fā)行,是OpenAI的最新產(chǎn)品。像GPT1,GPT2,GPT3和指令之前一樣,ChatGPT是一種Generative PretrainTed Transformer(GPT)模型,這是一種具有“self - attention”概念的語言模型,它允許該模型靈活地識別哪些部分是有效輸入。
大語言模型(LLMs)經(jīng)過大量文本數(shù)據(jù)(例如書籍和文章)的訓(xùn)練,以了解人類語言的模式和結(jié)構(gòu)。這使他們能夠生成聽起來更符合人類講話習(xí)慣的文本,從而使它們對于語言翻譯類和問答類等任務(wù)非常有效。
在過去的幾年中,LLMs一直在迅速增長。這些模型的規(guī)模成倍增加:盡管2017年推出的第一個 Transformer 模型具有6500萬個參數(shù) —— GPT3,直到2021年中,仍具有1750億個參數(shù)。隨著它們規(guī)模的增大,其表達(dá)能力也迅速加強。ChatGPT 是在更新版本的GPT3的最新版本中創(chuàng)建的,稱為GPT3.5。這種巨大的表達(dá)能力以及對其進(jìn)行訓(xùn)練的數(shù)據(jù)(大概與GPT3相似),使得 ChatGPT 如此有能力理解包括各種人類和編程語言,數(shù)字方程式和和弦的輸入。
作為一種生成模型,ChatGPT是專門設(shè)計的,旨在根據(jù)其從訓(xùn)練數(shù)據(jù)中學(xué)到的模式創(chuàng)建新文本。聊天機器人不僅可以及時給出響應(yīng),而且還能夠集成用戶提供的反饋,以更好地完成所需的任務(wù)。當(dāng)然,這不是完美的,但是此功能為一系列交互式應(yīng)用打開了新的大門。
僅供參考:本節(jié)中的三個句子由Chatgpt撰寫。我會讓你猜測哪一個!
ChatGPT擅長的地方
據(jù)我所知,ChatGPT 在計算機視覺應(yīng)用程序方面,比較可靠的主要有三類:commonplace code,dressed individual method calls 和 clean concatenations of simple components。ChatGPT對這三個類別中任何一個中的查詢的回答都比較令人滿意。我將舉例說明每個例子。
commonplace code
這應(yīng)該不足為奇,但是一個接受過包括文本和代碼在內(nèi)的大型語料庫訓(xùn)練的生成模型,通常非常擅長生成頻繁出現(xiàn)且在互聯(lián)網(wǎng)上幾乎沒有變化的代碼塊。當(dāng)基于代碼的解決方案基本上是規(guī)范的(并且可能在訓(xùn)練數(shù)據(jù)中無處不在)時,ChatGPT 的概率偏好將以很高的概率生成經(jīng)過驗證的真實結(jié)果。
這方面的兩個例子包括在信號處理和計算機視覺(以及其他領(lǐng)域)中無處不在的快速傅里葉變換(FFT) :
import numpy as npdef fft(x):"""Compute the discrete Fourier Transform of the 1D array x"""x = np.asarray(x, dtype=float)N = x.shape[0]if N <= 1: # base casereturn x# split the array into even and odd componentseven = fft(x[0::2])odd = fft(x[1::2])# compute the FFT of the even and odd componentsT = [np.exp(-2j*np.pi*k/N)*odd[k] for k in range(N//2)]return np.concatenate([even + T, even - T])
池化層,這是所有卷積神經(jīng)網(wǎng)絡(luò)必不可少的組成部分(CNN):
def min_pooling(inputs, pool_size):# Get the dimensions of the input arrayn_rows, n_cols, n_channels = inputs.shape# Calculate the size of the output arrayout_rows = n_rows // pool_sizeout_cols = n_cols // pool_size# Create an empty array to store the outputoutputs = np.zeros((out_rows, out_cols, n_channels))# Iterate over the input array and compute the outputfor r in range(out_rows):for c in range(out_cols):for k in range(n_channels):# Extract a patch of the input arraypatch = inputs[r*pool_size:(r+1)*pool_size, c*pool_size:(c+1)*pool_size, k]# Compute the min of the patchoutputs[r, c, k] = np.min(patch)return outputs
當(dāng)然,這些實現(xiàn)并不總是有效的,比如上面的 min _ pool() 函數(shù),它使用嵌套的 for 循環(huán)。對于像 ChatGPT 這樣的半黑盒人工智能模型,我們并不總是清楚這種解決方案是為了方便而有意選擇的,或者它真的選擇了它認(rèn)為是最優(yōu)的解決方案。在這樣的場景中,您可以使用 ChatGPT 以反饋為導(dǎo)向的特性來請求改進(jìn)。例如,在共享的情況下,可以指示 ChatGPT 并行化代碼或向量化 for 循環(huán)。知道要求哪些改進(jìn)是絕對必要的!
Dressed method calls
同樣,ChatGPT 對所有常見的機器學(xué)習(xí)和計算機視覺庫(直到2021年)都有很好的掌握,包括 PyTorch、 TensorFlow、 Scikit-learn、 PIL、 Skimage 和 OpenCV。當(dāng)聊天機器人可以調(diào)用這些庫中修飾方法進(jìn)行適當(dāng)?shù)念A(yù)處理步驟(如輸入輸出處理、將彩色圖像轉(zhuǎn)換為灰度以及 reshape 數(shù)組),可以處于最佳狀態(tài)。
這方面的一些例子,從最簡單到最復(fù)雜,都在銳化圖像:
from PIL import Image, ImageFilter# Open the imageim = Image.open('image.jpg')# Apply a sharpening filtersharpened_im = im.filter(ImageFilter.SHARPEN)# Save the sharpened imagesharpened_im.save('sharpened_image.jpg')
使用 Otsu 閾值:
from skimage import iofrom skimage.filters import threshold_otsu# Load the imageimage = io.imread('image.png')# Convert the image to grayscalegray_image = np.mean(image, axis=2)# Calculate the Otsu thresholdthreshold = threshold_otsu(gray_image)# Apply the threshold to the image to create a binary imagebinary_image = gray_image > threshold
并計算一組圖像的 tail-distributed stochastic neighbor(t-SNE):
import numpy as npfrom scipy.spatial.distance import pdist, squareformfrom sklearn.manifold import TSNEfrom scipy.spatial.distance import pdist, squareformfrom PIL import Imagedef tsne(images, perplexity=30.0, learning_rate=200.0, n_components=2):# Convert the images to grayscalegrayscale_images = [np.array(image.convert('L')) for image in images]# Stack the grayscale images into a single arraystacked_images = np.stack(grayscale_images)# Flatten the stacked images into a single arrayflattened_images = stacked_images.reshape(len(images), -1)# Compute the pairwise distances between the flattened imagesdistances = squareform(pdist(flattened_images, 'euclidean'))# Compute the low-dimensional embedding of the images using t-SNEtsne = TSNE(perplexity=perplexity, learning_rate=learning_rate, n_components=n_components, init='random')embedding = tsne.fit_transform(distances)return embedding
不幸的是,ChatGPT 并不熟練,甚至不熟悉新的CV庫,比如 FiftyOne。
Concatenating simple components
雖然 ChatGPT 的行為肯定是非理性的,但是模型具有基本的邏輯功能,可以將多個(簡單的)輸入合成到復(fù)合輸出中:只需向 ChatGPT 詢問表單中的一些問題
“ X 和 Y 有什么共同點”?
例如,我要求 ChatGPT 執(zhí)行以下操作:
”編寫代碼將兩個圖像的大小調(diào)整為(100,200) ,將數(shù)據(jù)集增加6個圖像,將所有輸入圖像合并為一個圖像,然后將所有圖像繪制在一個網(wǎng)格中。把這個提示寫在第三個圖上“
它的解決方案是這樣:
import matplotlib.pyplot as pltfrom skimage import io, transformfrom skimage.util import random_noise# load and resize imagesimg1 = io.imread("image1.png")img1 = transform.resize(img1, (100, 200))img2 = io.imread("image2.png")img2 = transform.resize(img2, (100, 200))# augment dataset with 6 additional imagesaugmented_imgs = []for i in range(6):augmented_imgs.append(random_noise(img1))augmented_imgs.append(random_noise(img2))# blend imagesblended_img = img1 * 0.5 + img2 * 0.5for img in augmented_imgs:blended_img += img * 0.5 / len(augmented_imgs)# plot all images in a gridfig, ax = plt.subplots(nrows=3, ncols=3)ax[0, 0].imshow(img1)ax[0, 1].imshow(img2)ax[0, 2].imshow(blended_img)for i in range(6):ax[1 + i // 3, i % 3].imshow(augmented_imgs[i])# add text to third plotax[0, 2].set_title("Resized, augmented, and blended images")
令人驚奇的其他地方
它也能夠毫無問題地完成其他任務(wù)包括:
1. 在三維點云上執(zhí)行分割(使用 DBSCAN)
2. 使用 DeOldify 恢復(fù)舊圖像的顏色
3. 在視頻中執(zhí)行目標(biāo)跟蹤
面臨的挑戰(zhàn)
在經(jīng)過和 ChatGPT 進(jìn)行有關(guān)”計算機視覺“任務(wù)的交流之后,似乎仍然存在之前反復(fù)出現(xiàn)的問題:long-tail scenarios, mathy manipulations, 和 expansive code blocks。與前一節(jié)一樣,我將給出每個例子。
Long tail
在任何領(lǐng)域,都會有各種各樣的任務(wù),這些任務(wù)是某些子領(lǐng)域的主要內(nèi)容,但是與用于訓(xùn)練 LLMs 的龐大語料庫中更常見的主題相比,它們相形見絀。ChatGPT 在這些領(lǐng)域有相當(dāng)一部分的問題,并且在小眾主題上提示時對細(xì)節(jié)非常敏感。
這方面的一個例子是 3D 計算機視覺,這是一個小但強大的子領(lǐng)域計算機視覺涉及三維空間數(shù)據(jù)。ChatGPT 有關(guān)于點云的工作知識,
“點云是 3D 空間中的一組點,代表一個物體的表面。點云中的每個點都由它的 3D 坐標(biāo)(x,y 和 z)定義,還可能包括其他信息,如顏色或法向量。點云通常用于計算機視覺和 3D 建模應(yīng)用”
當(dāng)我要求它“編寫代碼來定義作用于點云的 PointNet 體系結(jié)構(gòu)”時,它的回復(fù)包括 symmetric max pooling 函數(shù),該函數(shù)允許模型直接作用于非結(jié)構(gòu)化的點云數(shù)據(jù)。
import tensorflow as tf# Define the input layerinput_layer = tf.keras.layers.Input(shape=(None, 3))# Use a shared MLP to process the input point cloudmlp1 = tf.keras.layers.Dense(64, activation="relu")mlp2 = tf.keras.layers.Dense(64, activation="relu")mlp3 = tf.keras.layers.Dense(64, activation="relu")x = mlp1(input_layer)x = mlp2(x)x = mlp3(x)# Use max pooling to get the features of the entire point cloudglobal_features = tf.keras.layers.GlobalMaxPooling1D()(x)# Use a fully connected layer to predict the outputoutput_layer = tf.keras.layers.Dense(units=1, activation=None)(global_features)# Create the modelmodel = tf.keras.Model(inputs=input_layer, outputs=output_layer)
”這段代碼定義了一個 PointNet 體系結(jié)構(gòu),它接受一個點云作為輸入,并使用一個共享的多層感知器(MLP)來獨立處理每個點。然后,每個點的 MLP 輸出通過一個全局最大池化層傳遞,該層提取整個點云的特征。最后,根據(jù)點云的全局特征,采用一個全連接層來預(yù)測輸出。
這只是 PointNet 體系結(jié)構(gòu)的一種可能的實現(xiàn),根據(jù)項目的具體需求,可以對體系結(jié)構(gòu)進(jìn)行許多不同的變化和修改。”
當(dāng)我只提示 ChatGPT“為 PointNet 模型體系結(jié)構(gòu)編寫代碼”(省略了點云的明確提示)時,我得到的回應(yīng)如下:
import torchfrom torch import nnclass PointNet(nn.Module):def __init__(self):super(PointNet, self).__init__()# define the neural network layersself.fc1 = nn.Linear(3, 64)self.fc2 = nn.Linear(64, 64)self.fc3 = nn.Linear(64, 64)self.fc4 = nn.Linear(64, 128)self.fc5 = nn.Linear(128, 1024)self.fc6 = nn.Linear(1024, 512)self.fc7 = nn.Linear(512, 256)self.fc8 = nn.Linear(256, 128)self.fc9 = nn.Linear(128, 64)self.fc10 = nn.Linear(64, 10)def forward(self, x):# apply the neural network layers to the input point cloudx = F.relu(self.fc1(x))x = F.relu(self.fc2(x))x = F.relu(self.fc3(x))x = F.relu(self.fc4(x))x = F.relu(self.fc5(x))x = F.relu(self.fc6(x))x = F.relu(self.fc7(x))x = F.relu(self.fc8(x))x = F.relu(self.fc9(x))x = self.fc10(x)return x
”此代碼定義一個從 nn.Module 擴展的 PointNet 類。PointNet 類定義了一個具有10個全連接層的神經(jīng)網(wǎng)絡(luò),這些層在該類的 __init__ 方法中定義。forward 方法將這些層應(yīng)用于輸入點云并返回模型的輸出。
要使用 PointNet 模型,我們將創(chuàng)建 PointNet 類的一個實例,然后在輸入點云上調(diào)用 forward 方法。模型的輸出將是一個形狀為 (1,10) 的張量,其中包含了模型對輸入點云的預(yù)測”。
Math manipulations get messy
雖然 ChatGPT 能夠解決令人驚訝的獨立數(shù)學(xué)問題,甚至能夠生成自己的證明,但是聊天機器人卻很難將多行數(shù)學(xué)代碼串在一起。例如,當(dāng)被要求在不使用計算機視覺庫的情況下實現(xiàn) Otsu 閾值或霍夫變換時,ChatGPT 就會失敗。
Otsu 閾值:
def otsus_method(img):# calculate histogram of grayscale valueshistogram = np.zeros(256)for i in range(img.shape[0]):for j in range(img.shape[1]):j]] += 1# normalize histogramhistogram = histogram / img.size# calculate cumulative sum of normalized histogramcumulative_sum = np.cumsum(histogram)# calculate cumulative sum of squares of normalized histogramcumulative_sum_of_squares = np.cumsum(histogram ** 2)# initialize variablesoptimal_threshold = 0max_variance = 0# iterate over all possible threshold valuesfor i in range(256):# calculate background and foreground probabilitiesp_background = cumulative_sum[i]p_foreground = 1 - p_background# calculate meansmean_background = np.sum(np.arange(256) * histogram[:i+1]) / p_backgroundmean_foreground = np.sum(np.arange(i+1, 256) * histogram[i+1:]) / p_foreground# calculate between-class variancevariance = p_background * p_foreground * (mean_background - mean_foreground) ** 2# update optimal threshold if necessaryif variance > max_variance:max_variance = varianceoptimal_threshold = ireturn optimal_threshold

運行 ChatGPT 生成的 Otsu 閾值代碼后拋出錯誤
霍夫變換:
def hough_transform(img, theta_resolution=1, rho_resolution=1):# convert image to grayscaleimg = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)# detect edges in the image using Canny edge detectionedges = cv2.Canny(img, 50, 200)# create accumulator array with dimensions determined by theta and rho resolutionstheta = np.linspace(-90, 90, 180 // theta_resolution)rho = np.linspace(-np.sqrt(2) * img.shape[0], np.sqrt(2) * img.shape[0], 2 * np.sqrt(2) * img.shape[0] // rho_resolution)accumulator = np.zeros((len(theta), len(rho)))# find non-zero edge pixels in the imagex_idxs = np.nonzero(edges)# convert x and y indices to cartesian coordinatespoints = np.stack([x_idxs, y_idxs], axis=1)# iterate over all edge pointsfor x, y in points:# iterate over all theta valuesfor i, t in enumerate(theta):# calculate rho for current theta valuer = x * np.cos(t) + y * np.sin(t)# find closest rho value and increment corresponding accumulator binj = np.argmin(np.abs(rho - r))j] += 1return accumulator, theta, rho

運行 ChatGPT 生成的 Hough 轉(zhuǎn)換代碼后引發(fā)的錯誤
在許多情況下,高級邏輯流并不一定是錯誤的,或者至少不會太離譜。相反,在某行代碼上的調(diào)整,可能會引起上下文代碼的沖突:當(dāng) Otsu 閾值代碼試圖將不兼容形狀的操作數(shù)一起進(jìn)行廣播操作時,它失敗了。
其中一些數(shù)學(xué)錯誤很容易糾正,無論是通過將 int 轉(zhuǎn)換為 float,還是重寫代碼。其他時間,這些表面上的錯誤可能掩蓋了更多潛在的問題。如果您打算使用 ChatGPT 處理這些類型的問題,請謹(jǐn)慎處理。可以讓 ChatGPT 編寫的代碼越模塊化越好。
Expansive solutions breed errors
這可能不會太令人驚訝,但是生成的代碼越多,就越有可能出現(xiàn)錯誤(或多個錯誤)。畢竟,人們可以很容易地爭辯說,人類是一樣的。對于 Transformer 模型,一個眾所周知的問題是,隨著輸出中“塊”數(shù)的增加,相干性(和模型性能)降低。包含計算機視覺代碼的塊也不例外。
例如,當(dāng)我要求 ChatGPT“從頭開始實現(xiàn)光學(xué)字符識別(OCR)”時,該模型無可挽回地失敗了。這次失敗與其說是一系列可以理解的數(shù)學(xué)錯誤,不如說是一個完全的混亂。
當(dāng)然,這并不意味著 ChatGPT 無法執(zhí)行 OCR。
當(dāng)我提示聊天機器人“應(yīng)用光學(xué)字符識別”時,它表明至少它知道如何在 pytesseract 中使用相關(guān)方法:
import pytesseract# Load the license plate image# image = cv2.imread("license_plate.png")# Convert the image to grayscalegray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)# Apply Otsu's thresholding to binarize the imagethreshold, binary = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY+cv2.THRESH_OTSU)# Use Tesseract to perform OCR on the license plate imagetext = pytesseract.image_to_string(binary, lang="eng")# Print the recognized textprint(text)
當(dāng) ChatGPT 在 PyTorch、 TensorFlow 或 Sklearn 構(gòu)建神經(jīng)網(wǎng)絡(luò)時,這個問題經(jīng)常會暴露出來,在這些網(wǎng)絡(luò)中,它可能會以一種無法完成任何使用任務(wù)的方式將一系列層串在一起。
在哪些方面需要極度謹(jǐn)慎
前三個類別只是觸及了計算機視覺中使用 ChatGPT 可能出現(xiàn)問題的表面。在某些方面,人工智能也可能會給你錯得離譜的答案。
當(dāng)我請求 ChatgPT 給我“10個最佳目標(biāo)檢測模型的推斷時間年份”時,我得到了下面回應(yīng):
# Define the names and years of the 10 best object detection modelsmodel_names = ["Faster R-CNN", "YOLOv3", "SSD", "RetinaNet", "Mask R-CNN", "R-FCN", "SSD with FPN", "YOLOv4", "Grid R-CNN", "FCOS"]model_years = [2015, 2018, 2016, 2017, 2017, 2016, 2017, 2020, 2019, 2019]# Define the inference times of the 10 best object detection models (in milliseconds)model_inference_times = [100, 30, 20, 40, 60, 50, 25, 15, 35, 45]
粗略一看,這似乎相當(dāng)可信。這些模型在目標(biāo)檢測上都相當(dāng)有名ーー而且“最佳”在某種程度上有些主觀。年份也核實過了。所有這些都在推理時間上出現(xiàn)了問題。這些時間來自不同的來源,都有不同的條件和假設(shè)。ChatGPT 的回應(yīng)讓人覺得他們可以把蘋果比作蘋果,這顯然是錯誤的。
問一個關(guān)于推理時間這種模糊問題是一個糟糕的開始。但是,即使是更好的問題也可能給出錯誤的答案。
同樣,每當(dāng) ChatGPT 給出沒有作為示例顯式給出的特定數(shù)值時,您可能應(yīng)該小心。有時候這些值是合適的,比如當(dāng)它知道用給定的平均值和標(biāo)準(zhǔn)差規(guī)范化 AlexNet 時:
當(dāng)我要求 ChatGPT 使用立體圖像執(zhí)行深度知覺時,它包含了一行代碼,內(nèi)容如下:
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]當(dāng)被問及為什么選擇這些值時,它回應(yīng):
# Calculate the depth of each pixeldepth = 9.0 * 0.54 / (disparity + 0.00001)
“這個公式利用立體相機系統(tǒng)的已知參數(shù),例如基線(兩個相機之間的距離)和焦距,將視差值(左右圖像中像素水平位置的差異)轉(zhuǎn)換為深度值。”
這個公式中使用的特定值(9.0和0.54)只是示例,它們可能不適用于所有的立體相機系統(tǒng)。一般來說,根據(jù)視差計算深度的公式是:
depth = baseline * focal_length / (disparity + epsilon)其中 baseline 是兩個攝像機之間的距離,focal_length 是攝像機的焦距,disparity 是從立體圖像中計算出來的視差圖,epsilon 是用來避免被零除的一個小值。這些參數(shù)的值將取決于您所使用的特定立體攝像系統(tǒng)”。
另一個值得關(guān)注的領(lǐng)域是數(shù)據(jù)集和模型質(zhì)量的評估。當(dāng)被要求編寫“評估圖像數(shù)據(jù)集的質(zhì)量和多樣性”的代碼時,ChatGPT 給出了以下代碼:
import osfrom PIL import Imagefrom sklearn.neighbors import NearestNeighbors# Define the path to the dataset directorydataset_dir = './dataset'# Load the images in the datasetimages = []for filename in os.listdir(dataset_dir):# Load the imageimage = Image.open(os.path.join(dataset_dir, filename))# Convert the image to grayscale and resize it to a fixed sizeimage = image.convert('L').resize((128, 128))# Add the image to the list of imagesimages.append(image)# Flatten the images into a single arrayflattened_images = np.stack([np.array(image) for image in images]).reshape(len(images), -1)# Compute the nearest neighbors of the flattened imagesnbrs = NearestNeighbors(n_neighbors=5).fit(flattened_images)distances, indices = nbrs.kneighbors(flattened_images)# Compute the mean and standard deviation of the distances to the nearest neighborsmean_distance = np.mean(distances[:, 1:])std_distance = np.std(distances[:, 1:])print('Mean distance to nearest neighbor:', mean_distance)print('Standard deviation of distances:', std_distance)
同時還附上了一個說明:
”在本例中,images 變量是數(shù)據(jù)集中的圖像列表。首先從磁盤上的文件加載圖像,然后使用 PIL.Image 模塊中的 Convert 和 resize 方法將圖像轉(zhuǎn)換為灰度并調(diào)整到固定大小。然后使用堆棧和從數(shù)字模塊重塑圖像形狀的方法將圖像壓平成一個單獨的數(shù)組。nbrs 變量使用來自 skLearn.friends 模塊的 NearestNeighbors 類計算圖像的最近鄰。mean_distance 和 std_distance 變量計算到最近鄰的距離的均值和標(biāo)準(zhǔn)差,這可以作為衡量數(shù)據(jù)集質(zhì)量和多樣性的指標(biāo)。平均距離越短,標(biāo)準(zhǔn)差越高,說明數(shù)據(jù)集的質(zhì)量越高,種類也越多。”
盡管這種方法并不一定是錯誤的,或者在技術(shù)上是錯誤的,但它至少是非常簡單的。
當(dāng)我要求 ChatGPT 計算一個圖像數(shù)據(jù)集中的分布偏移時,我得到了一個類似的令人沮喪的答案,它對原始像素值使用了 t 檢驗(一個只比較兩組樣本平均值的檢驗)。你也可以看到,ChatGPT 試圖計算兩組圖像之間的均方差,這只有在圖像大小相同的情況下才有意義,但是我們在這里會給聊天機器人一點懷疑的余地,然后繼續(xù)下一步。
# Import necessary librariesimport numpy as npfrom scipy.stats import ttest_indfrom sklearn.metrics import mean_squared_error# Load the original and new datasetsoriginal_data = ...new_data = ...# Calculate the mean squared error between the original and new imagesmse = mean_squared_error(original_data, new_data)# Use a t-test to compare the means of the original and new datasetst, p = ttest_ind(original_data, new_data)# Print the resultsprint("Mean squared error:", mse)print("T-test results: t =", t, "p =", p)# If the mean squared error is large and the t-test p-value is small,# this indicates a significant distribution shift in the data
計算機器學(xué)習(xí)中的分布變化通常是一個困難的問題,但至少對各種類型的可能變化的基本理解是標(biāo)準(zhǔn)的,有多種比應(yīng)用 t 檢驗更微妙的方法。
最后一個例子是有啟發(fā)性的:我提示 ChatGPT“計算我的模型被給予一組基本真值、預(yù)測和預(yù)測置信度得分的錯誤程度”,它的回答的關(guān)鍵是“你可以使用一個像準(zhǔn)確度或精確度這樣的度量來衡量你的模型的表現(xiàn)”,這完全錯過了分?jǐn)?shù),而且根本沒有使用置信度得分。作為參考,在開源計算機視覺庫 FiftyOne 中,可以通過調(diào)用 dataset.cdomputer_mistakenness() 為 dataset 數(shù)據(jù)集計算這種類型的數(shù)量。
為什么可以為 ChatGPT 授予CV工程師
然而,盡管有這些缺點,ChatGPT 仍然可以成為計算機視覺領(lǐng)域的一股力量。至少這是一個人的觀點。
您可能已經(jīng)注意到了我所包含的示例中的一個主題。ChatGPT 是一個工具,可以幫助計算機視覺工程師和從業(yè)人員更有效地完成他們的工作。這是一個非常強大的工具,也可以是相當(dāng)”危險“的。就像任何工具一樣,它的好壞取決于它的使用者如何使用。
從編程的角度來看,和許多優(yōu)秀的人類工程學(xué)能夠產(chǎn)生優(yōu)秀的機器生成代碼的原則是相同的:以模塊化設(shè)計為目標(biāo),如果可能的話將高級任務(wù)分解為多個部分,利用現(xiàn)有的庫而不是重造輪子。
如果使用得當(dāng),ChatGPT 可以幫助CV工程師更快地編寫CV代碼,使人們可以利用 Scale、 V7和 Voxel51等公司的工具集,專注于建立高質(zhì)量的數(shù)據(jù)集和評估機器學(xué)習(xí)模型等重要任務(wù)。
計算機視覺工具集
FiftyOne 是由 Voxel51開發(fā)的一個開源機器學(xué)習(xí)工具集,它使數(shù)據(jù)科學(xué)團隊能夠通過幫助他們管理高質(zhì)量的數(shù)據(jù)集,評估模型,發(fā)現(xiàn)錯誤,可視化嵌入,更快地進(jìn)入生產(chǎn),從而提高他們的計算機視覺模型的性能。


