查看您在评论中提供的链接,您的模型定义看起来像这样:
class SegmentationModel(nn.Module):
def __init__(self):
super(SegmentationModel,self).__init__()
self.arc = smp.Unet(
encoder_name = ENCODER,
encoder_weights = WEIGHTS,
in_channels = 3,
classes = 1,
activation = None
)
def forward(self, images, masks = None):
logits = self.arc(images)
if masks != None:
loss1 = DiceLoss(mode = 'binary')(logits, masks)
loss2 = nn.BCEWithLogitsLoss()(logits,masks)
return logits, loss1 + loss2
return logits
如果您近距离看,您会看到 forward()
具有不稳定的额外凹痕,使其成为内部功能 __ INIT __()
而不是 SemengeationModel
的方法。将其转移到左侧,应该很好地工作:
class SegmentationModel(nn.Module):
def __init__(self):
super(SegmentationModel,self).__init__()
self.arc = smp.Unet(
encoder_name = ENCODER,
encoder_weights = WEIGHTS,
in_channels = 3,
classes = 1,
activation = None
)
def forward(self, images, masks = None):
logits = self.arc(images)
if masks != None:
loss1 = DiceLoss(mode = 'binary')(logits, masks)
loss2 = nn.BCEWithLogitsLoss()(logits,masks)
return logits, loss1 + loss2
return logits
模块查找是根据模块搜索路径进行的,您可以使用 PythonPath
环境变量覆盖该路径。例如,如果 modulec
是在/some/other/directory/modulec.py
中安装
PYTHONPATH=/some/other/directory python -m mymodule
的在搜索默认目录之前,代码>/某些/其他/目录。
请注意,Python并不真正支持在同一过程中使用在不同目录中安装的多个版本的模块。如果您只想使用 modulec
myModule
的特定版本,但请使用同一脚本中其他位置的全系统版本,则必须安装两个版本 myModule
在不同的名称下。
你做不到。
Google Analytics(分析)中保存的数据无法更改。
我将使用gnu awk
进行此任务以下方式,让 file.txt
-1.3 -2.00 -3.00 4.00 9.00
0.10 -0.20 -0.80 4.50 1.70
0.00 -3.40 -6.80 5.60 9.30
-0.4 -3.20 -4.70 0.80 -0.9
1.03 -2.00 -3.00 4.00 9.00
0.00 -6.80 -9.30 3.40 5.60
0.00 -4.70 -0.80 8.90 -0.3
进行
awk '!($1=="0.00")' file.txt
输出
-1.3 -2.00 -3.00 4.00 9.00
0.10 -0.20 -0.80 4.50 1.70
-0.4 -3.20 -4.70 0.80 -0.9
1.03 -2.00 -3.00 4.00 9.00
说明:单个条件只需描述您想要的行:不(>) !
)第一个字段( $ 1
)为( ==
)字符串 0.00
(“ 0.00”
)
(已测试Gawk 4.2.1)
var MalathysStudents = studentlist.Where(s=>s.TeacherId==1).ToList();
那一个人呢,
var string = "Please click on dashboard and then open the dashboard details to verify your details on the data";
const stringArray = string.split(' ');
var targetTexts = ["dashboard" , "dashboard" , "data"]
var replaceTexts = ["https://abcd.com/login" , "https://abcd.com/home" , "https://abcd.com/data"]
const resultArray = []
for (let i = 0; i < stringArray.length; i++) {
const word = stringArray[i];
const targetTextIndex = targetTexts.indexOf(word);
if (targetTextIndex > -1) {
resultArray.push("<a href='"+replaceTexts[targetTextIndex]+"'>"+word+"</a>")
targetTexts = targetTexts.filter((_el, idx) => idx !== targetTextIndex)
replaceTexts = replaceTexts.filter((_el, idx) => idx !== targetTextIndex)
} else {
resultArray.push(word);
}
}
console.log(resultArray.join(' '))
我希望您对此有一个暗示。
它的工作就像魅力一样,将有例外处理供您处理。
这是一个非常简单的地方,可以使用列表理解来生成不包含任何关键字的项目列表。
>>> [f"{i} {t} {m}" for i, (t, m) in enumerate(zip(title, mama))
... if not any(w in m for w in filterkeywords)]
['0 SL C slow cat Sas', '5 SL C slow cat yan']
>>>
发电机表达式传递给任何
是否存在任何关键字的工作。我们使用 zip
将标题和元素组合在妈妈
中。 枚举
提供索引。
不,无法以这种方式检测到。
以下不是便携式解决方案,但它在 gcc 12.1, clang 14.0和 msvc 19.32。它可能停止在以后的版本中工作。
您需要首先设置 errno = 0;
,然后检查范围错误:
#include <errno.h>
// ...
errno = 0;
f = scanf("%d",&i);
if(f == 1 && errno != ERANGE) {
// success
}
对于可移植性,请从 C2X标准的早期草稿:
除非
*
表示抑制分配抑制
转换结果。如果此对象没有适当的类型,或者如果转换的结果无法在对象中表示,则行为是未定义的。
一个更好的(如 portable 中)检测到的选项是首先阅读到 char []
buffer,然后使用 strtol()
将其转换为数字。从相同的标准草稿中:
strtol
,strtoll
,strtoul
和strtoull
功能函数返回转换的值(如果有)。如果无法执行转换,则返回零。如果正确的值超出了表示值的范围,则long_min
,long_max
,llong_min
,llong_max
,ulong_max
或ullong_max
被返回(根据该值的返回类型和符号(如果有)的符号),以及宏erange
的值。在errno
中。
这是一个使用 strtol()
(转换为 long
)的例证程序:
#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
// A wrapper around `strtol` to convert to `int`
int strtoi(const char *str, char **str_end, int base) {
int errno_save = errno;
errno = 0; // clear it from any previous error (must be done)
long result = strtol(str, str_end, base);
if(errno == ERANGE) return result == LONG_MAX ? INT_MAX : INT_MIN;
if(result > INT_MAX || result < INT_MIN) {
errno = ERANGE;
return result > INT_MAX ? INT_MAX : INT_MIN;
}
// success or no conversion could be performed
errno = errno_save; // restore errno
return (int)result;
}
#define Size(x) (sizeof (x) / sizeof *(x))
int main(void) {
const char* strings[] = {
"3333333333333333333333 foo",
"2147483647 will probably succeed",
"2147483648 will probably fail",
"32767 guaranteed success",
"32767xyz",
"xyz",
"123",
""
};
char *end; // this will point at where the conversion ended in the string
for(unsigned si = 0; si < Size(strings); ++si) {
printf("testing \"%s\"\n", strings[si]);
errno = 0; // clear it from any previous error (must be done)
int result = strtoi(strings[si], &end, 10);
if(errno == ERANGE) {
perror(" to big for an int");
} else if(strings[si] == end) {
fprintf(stderr, " no conversion could be done\n");
} else if(*end != '\0' && !isspace((unsigned char)*end)) {
fprintf(stderr, " conversion ok,"
" but followed by a rouge character\n");
} else {
printf(" success: %d rest=[%s]\n", result, end);
}
}
}
可能的输出:
testing "3333333333333333333333 foo"
to big for an int: Numerical result out of range
testing "2147483647 will probably succeed"
success: 2147483647 rest=[ will probably succeed]
testing "2147483648 will probably fail"
to big for an int: Numerical result out of range
testing "32767 guaranteed success"
success: 32767 rest=[ guaranteed success]
testing "32767xyz"
conversion ok, but followed by a rouge character
testing "xyz"
no conversion could be done
testing "123"
success: 123 rest=[]
testing ""
no conversion could be done
您必须使用 self.owner
而不是所有者()
。如果要保留实例,则应附加 self
最小工作代码:
class Name:
def __init__(self, first, last):
self.first = first
self.last = last
class Owner:
def __init__(self, name):
self.name = name
self.pets = []
class Pet:
def __init__(self, name, owner):
self.name = name
self.owner = owner
self.owner.pets.append(self)
# --- main ---
person = Name('James', 'Bond')
owner = Owner(person)
pet1 = Pet("Lassie", owner)
pet2 = Pet("Kermit", owner)
pet3 = Pet("Jumbo", owner)
print('Owner:', owner.name.first, owner.name.last)
for pet in owner.pets:
print('Pet :', pet.name)
print('---')
print('Pet :', pet1.name)
print('Owner:', pet1.owner.name.first, pet1.owner.name.last)
print('---')
print('Pet :', pet2.name)
print('Owner:', pet2.owner.name.first, pet2.owner.name.last)
print('other Pets for the same Owner:')
for pet in pet2.owner.pets:
if pet != pet2:
print(' >', pet.name)
print('---')
结果:
Owner: James Bond
Pet : Lassie
Pet : Kermit
Pet : Jumbo
---
Pet : Lassie
Owner: James Bond
---
Pet : Kermit
Owner: James Bond
other Pets for the same Owner:
> Lassie
> Jumbo
---
SSH主持人不匹配confd。
我们再次复制了钥匙,然后开始工作
cp -f /etc/ssh/ssh_host_rsa_key /etc/ssh/ssh_host_rsa_key.pub /opt/confd/etc/confd/ssh
canvas.create_text正在显示图像下的文本,而不是在顶部。
我正在尝试创建_text并将其放在图像上,但是在运行时
我只能看到它甚至出现的代码,如果我在位置中创建它
0,0,位置400,263处的其他文本未显示(因为它
在图像下分层)
可以通过将字体大小减少到40和30来解决问题。并将canvas.create_text坐标设置为 canvas.create_text(120,30,...)
而不是 canvas.create_text(0,0,...)
snippet:
from tkinter import *
window = Tk()
window.title("Flash Card")
window.config(pady=50, padx=50, background='green')
canvas = Canvas(width=800, height=526)
french_background = PhotoImage (file ="p2.png")
canvas.create_image(400, 263, image=french_background)
canvas.create_text(120, 30, text="French", fill= "black" , font=("Ariel", 40, "italic"))
canvas.create_text(400,263, text='random_french', fill="yellow", font=("Ariel",30,"bold"))
canvas.config(bg='red', highlightthickness=0)
canvas.grid(row=0, column=0, columnspan=2)
window.mainloop()
screenshot:
formik.seterrors
应用于所有错误,{postalcode:'邮政编码中的错误'}
只是许多其他错误的特定错误,因此,当您将其设置为单独时,已经消除了所有其他字段的错误。在这种情况下,您应该将其他字段的错误
formik.errors
与更新的错误一起。formik.setErrors
is applied to all errors,{postalCode:'error in postal code' }
is only a particular error of many other errors, so when you set it singularly that has wiped out all other fields' errors.In this case, you should pass the other fields' errors
formik.errors
to that function along with your updated error.formik seterrors重置其他字段