BCEloss() در PyTorch – انجمن DEV

Summarize this content to 400 words in Persian Lang
برای من یک قهوه بخر☕
*یادداشت ها:
()BCEloss می تواند تانسور 0D یا بیشتر از مقادیر صفر یا بیشتر را دریافت کند.float) توسط BCE Loss از تانسور 0D یا بیشتر D از عناصر صفر یا بیشتر محاسبه می شود که در زیر نشان داده شده است:
*یادداشت ها:
آرگومان اول برای مقداردهی اولیه است weight(اختیاری-پیش فرض:None-نوع:tensor از int، float یا bool). اگر داده نشود، این است 1.
وجود دارد reduction آرگومان برای مقداردهی اولیه (اختیاری-پیش فرض:’mean’-نوع:str). *’none’، ‘mean’ یا ‘sum’ را می توان انتخاب کرد.
وجود دارد size_average و reduce آرگومان اولیه سازی اما منسوخ شده اند.
استدلال اول این است input(الزامی-نوع:tensor از float). *باید باشد 0.
استدلال دوم این است target(الزامی-نوع:tensor از float). *باید باشد 0.
input و target باید یک اندازه باشد در غیر این صورت یک هشدار وجود دارد.
1D خالی یا بیشتر D input و target تانسورها با reduction=’mean’ بازگشت nan.
1D خالی یا بیشتر D input و target تانسورها با reduction=’sum’ بازگشت 0..
import torch
from torch import nn
tensor1 = torch.tensor([0.4, 0.8, 0.6, 0.3, 0.0, 0.5])
tensor2 = torch.tensor([0.2, 0.9, 0.4, 0.1, 0.8, 0.5])
# -w(y*logx+(1-y)*log(1-x)))
# -1(0.2*log0.4+(1-0.2)*log(1-0.4))
# ↓↓↓↓↓↓
# 0.5919+0.3618+0.7541+0.4414+80.0+0.6931 = 82.8423
# 82.8423 / 6 = 13.8071
bceloss = nn.BCELoss()
bceloss(input=tensor1, target=tensor2)
# tensor(7.2500)
bceloss
# BCELoss()
bceloss.reduction
# ‘mean’
print(bceloss.weight)
# None
bceloss = nn.BCELoss(weight=None, reduction=’mean’)
bceloss(input=tensor1, target=tensor2)
# tensor(13.8071)
bceloss = nn.BCELoss(weight=None, reduction=’sum’)
bceloss(input=tensor1, target=tensor2)
# tensor(82.8423)
bceloss = nn.BCELoss(weight=None, reduction=’none’)
bceloss(input=tensor1, target=tensor2)
# tensor([0.5919, 0.3618, 0.7541, 0.4414, 80.0000, 0.6931])
bceloss = nn.BCELoss(weight=torch.tensor([0., 1., 2., 3., 4., 5.]))
bceloss(input=tensor1, target=tensor2)
# tensor(54.4433)
bceloss = nn.BCELoss(weight=torch.tensor([0.]))
bceloss(input=tensor1, target=tensor2)
# tensor(0.)
bceloss = nn.BCELoss(weight=torch.tensor([0, 1, 2, 3, 4, 5]))
bceloss(input=tensor1, target=tensor2)
# tensor(54.4433)
bceloss = nn.BCELoss(weight=torch.tensor([0]))
bceloss(input=tensor1, target=tensor2)
# tensor(0.)
bceloss = nn.BCELoss(
weight=torch.tensor([True, False, True, False, True, False])
)
bceloss(input=tensor1, target=tensor2)
# tensor(13.5577)
bceloss = nn.BCELoss(weight=torch.tensor([False]))
bceloss(input=tensor1, target=tensor2)
# tensor(0.)
tensor1 = torch.tensor([[0.4, 0.8, 0.6], [0.3, 0.0, 0.5]])
tensor2 = torch.tensor([[0.2, 0.9, 0.4], [0.1, 0.8, 0.5]])
bceloss = nn.BCELoss()
bceloss(input=tensor1, target=tensor2)
# tensor(13.8071)
tensor1 = torch.tensor([[[0.4], [0.8], [0.6]], [[0.3], [0.0], [0.5]]])
tensor2 = torch.tensor([[[0.2], [0.9], [0.4]], [[0.1], [0.8], [0.5]]])
bceloss = nn.BCELoss()
bceloss(input=tensor1, target=tensor2)
# tensor(13.8071)
tensor1 = torch.tensor([])
tensor2 = torch.tensor([])
bceloss = nn.BCELoss(reduction=’mean’)
bceloss(input=tensor1, target=tensor2)
# tensor(nan)
bceloss = nn.BCELoss(reduction=’sum’)
bceloss(input=tensor1, target=tensor2)
# tensor(0.)
وارد حالت تمام صفحه شوید
از حالت تمام صفحه خارج شوید
برای من یک قهوه بخر☕
*یادداشت ها:
()BCEloss می تواند تانسور 0D یا بیشتر از مقادیر صفر یا بیشتر را دریافت کند.float
) توسط BCE Loss از تانسور 0D یا بیشتر D از عناصر صفر یا بیشتر محاسبه می شود که در زیر نشان داده شده است:
*یادداشت ها:
- آرگومان اول برای مقداردهی اولیه است
weight
(اختیاری-پیش فرض:None
-نوع:tensor
ازint
،float
یاbool
). اگر داده نشود، این است1
. - وجود دارد
reduction
آرگومان برای مقداردهی اولیه (اختیاری-پیش فرض:'mean'
-نوع:str
). *'none'
،'mean'
یا'sum'
را می توان انتخاب کرد. - وجود دارد
size_average
وreduce
آرگومان اولیه سازی اما منسوخ شده اند. - استدلال اول این است
input
(الزامی-نوع:tensor
ازfloat
). *باید باشد0.
- استدلال دوم این است
target
(الزامی-نوع:tensor
ازfloat
). *باید باشد0.
-
input
وtarget
باید یک اندازه باشد در غیر این صورت یک هشدار وجود دارد. - 1D خالی یا بیشتر D
input
وtarget
تانسورها باreduction='mean'
بازگشتnan
. - 1D خالی یا بیشتر D
input
وtarget
تانسورها باreduction='sum'
بازگشت0.
.
import torch
from torch import nn
tensor1 = torch.tensor([0.4, 0.8, 0.6, 0.3, 0.0, 0.5])
tensor2 = torch.tensor([0.2, 0.9, 0.4, 0.1, 0.8, 0.5])
# -w(y*logx+(1-y)*log(1-x)))
# -1(0.2*log0.4+(1-0.2)*log(1-0.4))
# ↓↓↓↓↓↓
# 0.5919+0.3618+0.7541+0.4414+80.0+0.6931 = 82.8423
# 82.8423 / 6 = 13.8071
bceloss = nn.BCELoss()
bceloss(input=tensor1, target=tensor2)
# tensor(7.2500)
bceloss
# BCELoss()
bceloss.reduction
# 'mean'
print(bceloss.weight)
# None
bceloss = nn.BCELoss(weight=None, reduction='mean')
bceloss(input=tensor1, target=tensor2)
# tensor(13.8071)
bceloss = nn.BCELoss(weight=None, reduction='sum')
bceloss(input=tensor1, target=tensor2)
# tensor(82.8423)
bceloss = nn.BCELoss(weight=None, reduction='none')
bceloss(input=tensor1, target=tensor2)
# tensor([0.5919, 0.3618, 0.7541, 0.4414, 80.0000, 0.6931])
bceloss = nn.BCELoss(weight=torch.tensor([0., 1., 2., 3., 4., 5.]))
bceloss(input=tensor1, target=tensor2)
# tensor(54.4433)
bceloss = nn.BCELoss(weight=torch.tensor([0.]))
bceloss(input=tensor1, target=tensor2)
# tensor(0.)
bceloss = nn.BCELoss(weight=torch.tensor([0, 1, 2, 3, 4, 5]))
bceloss(input=tensor1, target=tensor2)
# tensor(54.4433)
bceloss = nn.BCELoss(weight=torch.tensor([0]))
bceloss(input=tensor1, target=tensor2)
# tensor(0.)
bceloss = nn.BCELoss(
weight=torch.tensor([True, False, True, False, True, False])
)
bceloss(input=tensor1, target=tensor2)
# tensor(13.5577)
bceloss = nn.BCELoss(weight=torch.tensor([False]))
bceloss(input=tensor1, target=tensor2)
# tensor(0.)
tensor1 = torch.tensor([[0.4, 0.8, 0.6], [0.3, 0.0, 0.5]])
tensor2 = torch.tensor([[0.2, 0.9, 0.4], [0.1, 0.8, 0.5]])
bceloss = nn.BCELoss()
bceloss(input=tensor1, target=tensor2)
# tensor(13.8071)
tensor1 = torch.tensor([[[0.4], [0.8], [0.6]], [[0.3], [0.0], [0.5]]])
tensor2 = torch.tensor([[[0.2], [0.9], [0.4]], [[0.1], [0.8], [0.5]]])
bceloss = nn.BCELoss()
bceloss(input=tensor1, target=tensor2)
# tensor(13.8071)
tensor1 = torch.tensor([])
tensor2 = torch.tensor([])
bceloss = nn.BCELoss(reduction='mean')
bceloss(input=tensor1, target=tensor2)
# tensor(nan)
bceloss = nn.BCELoss(reduction='sum')
bceloss(input=tensor1, target=tensor2)
# tensor(0.)