我目前正在学习使用Python的OpenCV API,这一切都很好.我正在取得不错的进展.部分内容来自Python语法的简单性,而不是将其与C++一起使用,我还没有尝试过.我已经意识到,如果我打算做任何生产质量,我必须在某些时候弄脏OpenCV的C++绑定.
就在最近,我遇到了dlib,它也声称可以完成OpenCV所做的所有事情.它用C++编写,也提供Python API(惊喜).任何人都可以根据自己的实施经验担保dlib吗?
我正在刷新我的"C"知识.我得到Arrays 衰减到指针以及它是如何工作的.在字符串处理中,我一直在运行看起来像这样的代码;
int count_spaces(const char *s)
{
int count = 0;
for(; *s != '\0'; s++){
if(*s == ' '){
count++;
}
}
return count;
}
Run Code Online (Sandbox Code Playgroud)
我从字符串处理代码中获得了什么性能提升而不是编写我的函数?
int count_spaces(const char s[])
{
int count = 0, i;
for(i = 0; s[i] != '\0'; i++)
{
if(s[i] == ' '){
count++;
}
}
return count;
}
Run Code Online (Sandbox Code Playgroud)
是否有一个简单的词典可供使用何时使用指针而何时不使用?
以下是使用PyTorch中的nn.functional()模块的前馈网络
import torch.nn.functional as F
class newNetwork(nn.Module):
def __init__(self):
super().__init__()
self.fc1 = nn.Linear(784, 128)
self.fc2 = nn.Linear(128, 64)
self.fc3 = nn.Linear(64,10)
def forward(self,x):
x = F.relu(self.fc1(x))
x = F.relu(self.fc2(x))
x = F.softmax(self.fc3(x))
return x
model = newNetwork()
model
Run Code Online (Sandbox Code Playgroud)
以下是使用nn.sequential()模块进行本质上相同构建的相同前馈。两者之间有什么区别?什么时候我可以使用一个而不是另一个?
input_size = 784
hidden_sizes = [128, 64]
output_size = 10
Run Code Online (Sandbox Code Playgroud)
model = nn.Sequential(nn.Linear(input_size, hidden_sizes[0]),
nn.ReLU(),
nn.Linear(hidden_sizes[0], hidden_sizes[1]),
nn.ReLU(),
nn.Linear(hidden_sizes[1], output_size),
nn.Softmax(dim=1))
print(model)
Run Code Online (Sandbox Code Playgroud)