x = x.view(x.size(0), -1)??????????
# view函數(shù)就是reshape,從1開(kāi)始癣漆,-1說(shuō)明自行計(jì)算行數(shù)或列數(shù)长赞,把多行多列的變成一行,全鏈接的輸入
nn.Linear(20, 30)
#相當(dāng)于執(zhí)行y = Wx + b态贤,全鏈接,從20變成30醋火,W是默認(rèn)隨機(jī)初始化的weight=Parameter(torch.Tensor(out_features, in_features)) [30,20]
loss_func = nn.CrossEntropyLoss()
loss = loss_func(output, b_y)
#計(jì)算交叉熵
預(yù)測(cè)的(0.0,1.0,0.0)
實(shí)際的(0.228,0.619,0.153)
H = - (0.0*ln(0.228) + 1.0*ln(0.619) + 0.0*ln(0.153)) = 0.479
import torch
import torchvision
import torchvision.transforms as transforms
import torchvision.utils as utils
from PIL import Image
import numpy as np
import cv2
img_path = "../img_66_pos_real/72264809151922400.jpg"
# transforms.ToTensor()
transform1 = transforms.Compose([ ? ??
????transforms.ToTensor(), # range [0, 255] -> [0.0,1.0]?歸一化
????]
)
##opencv
img = cv2.imread(img_path)
print("img = ", img)
img1 = transform1(img)
print("img1 = ",img1)
##PIL
img = Image.open(img_path).convert('RGB')
img2 = transform1(img)
print("img2 = ",img2)