- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在使用 OpenCV v2.4.1
这是我正在使用的代码
#include "opencv2/opencv.hpp"
#include <iostream>
#include <fstream>
#include <sstream>
using namespace cv;
using namespace std;
Mat toGrayscale(InputArray _src) {
Mat src = _src.getMat();
// only allow one channel
if(src.channels() != 1)
CV_Error(CV_StsBadArg, "Only Matrices with one channel are supported");
// create and return normalized image
Mat dst;
cv::normalize(_src, dst, 0, 255, NORM_MINMAX, CV_8UC1);
return dst;
}
void read_csv(const string& filename, vector<Mat>& images, vector<int>& labels, char separator = ';') {
std::ifstream file(filename.c_str(), ifstream::in);
if (!file)
throw std::exception();
string line, path, classlabel;
while (getline(file, line)) {
stringstream liness(line);
getline(liness, path, separator);
getline(liness, classlabel);
images.push_back(imread(path, 0));
labels.push_back(atoi(classlabel.c_str()));
}
}
int main(int argc, const char *argv[]) {
// check for command line arguments
/*if (argc != 2) {
cout << "usage: " << argv[0] << " <csv.ext>" << endl;
exit(1);
}*/
// path to your CSV
string fn_csv = string("at.txt");
// images and corresponding labels
vector<Mat> images;
vector<int> labels;
// read in the data
try {
read_csv(fn_csv, images, labels);
} catch (exception&) {
cerr << "Error opening file \"" << fn_csv << "\"." << endl;
exit(1);
}
// get width and height
//int width = images[0].cols;
int height = images[0].rows;
// get test instances
Mat testSample = images[images.size() - 1];
int testLabel = labels[labels.size() - 1];
// ... and delete last element
images.pop_back();
labels.pop_back();
// build the Fisherfaces model
Ptr<FaceRecognizer> model = createFisherFaceRecognizer();
model->train(images, labels);
// test model
int predicted = model->predict(testSample);
cout << "predicted class = " << predicted << endl;
cout << "actual class = " << testLabel << endl;
// get the eigenvectors
Mat W = model->eigenvectors();
// show first 10 fisherfaces
for (int i = 0; i < min(10, W.cols); i++) {
// get eigenvector #i
Mat ev = W.col(i).clone();
// reshape to original size AND normalize between [0...255]
Mat grayscale = toGrayscale(ev.reshape(1, height));
// show image (with Jet colormap)
Mat cgrayscale;
applyColorMap(grayscale, cgrayscale, COLORMAP_JET);
imshow(format("%d", i), cgrayscale);
}
waitKey(0);
return 0;
}
at.txt 输入文件的内容:
./at/s10/2.pgm;9./at/s10/7.pgm;9./at/s10/6.pgm;9./at/s10/9.pgm;9./at/s10/5.pgm;9
现在的问题是,只要我在使用这个 pgm 文件,它就可以正常工作。但是当我指定任何 jpg 文件而不是 pgm 时,我得到以下错误
OpenCV 错误:图像步长错误(矩阵不连续,因此其编号 行数不能更改)在未知函数中,文件......\src\opencv\modules\core\src\matrix.cpp,第801行
到目前为止,我能够追踪到错误来自 Fisherfaces.train() --> cv::Mat.reShape()
但是我一头雾水,请问是什么原因。请帮忙。
最佳答案
This solution对我有用!
之前我在项目属性中添加了发布和调试库。现在我已经删除了所有已发布的库,并且它可以完美地工作。
关于opencv - 在 Fisherfaces.train() 方法中获取 OpenCV 错误 "Image step is wrong",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10961586/
TensorFlow 提供了 3 种不同的数据存储格式 tf.train.Feature .它们是: tf.train.BytesList tf.train.FloatList tf.train.In
在我的设置中,我运行了一个脚本 火车一个模型并开始生成检查点。另一个脚本监视新的检查点和 评估 他们。脚本并行运行,因此评估只是训练之后的一步。 支持这种情况的正确 Tracks 配置是什么? 最佳答
什么是合理的设置?我可以在同一次执行中多次调用 Task.init() 吗? 最佳答案 免责声明:我是 allegro.ai Trains 团队的一员 一种解决方案是从 trains.automati
我想开始我的方式 ClearML (以前称为火车)。 我在documentation上看到的我需要在 ClearML 平台本身或使用 AWS 等的远程机器上运行服务器。 我真的很想绕过这个限制并在我的
我正在尝试使用 weka 的 MultilayerPerceptron 执行以下操作: 使用一小部分训练实例来训练一部分历元输入, 在剩余的周期中使用整组实例进行训练。 但是,当我在代码中执行以下操作
这个问题与对象检测有关,基本上是检测任何“已知”对象。例如,假设我有以下对象。 表格 瓶子。 相机 汽车 我将从所有这些单独的对象中拍摄 4 张照片。左边一个,右边一个,上下两个。我本来以为用这4张照
我已经编写了一段代码来训练Guassian过程回归模型来预测年龄。我已经编写了以下代码,并且运行良好:。但我注意到,每个纪元都输入了相同的数据,我认为这可能会导致过度拟合,所以我想使用Mini Bat
(一)、tf.train.Saver() (1). tf.train.Saver() 是用来保存tensorflow训练模型的,默认保存全部参数 (2). 用来加载参数,注:只加载存储在data
我是 PyTorch 的新手,我想知道您是否可以向我解释 PyTorch 中的默认 model.train() 与此处的 train() 函数之间的一些关键区别。 另一个 train() 函数位于关于
我可以在maskrcnn的预训练模型的基础上训练吗?如果预训练模型的类别与我自己的数据集不同,预训练模型仍然有效吗?。我尝试了一个新的班级训练数据集。但它似乎收敛得非常慢。
我可以按照Maskrcnn预先训练的模式进行训练吗?如果预先训练的模型的类别与我自己的数据集的类别不同,那么预先训练的模型是否仍然有效?。我尝试了一个新的班级训练数据集。但它似乎收敛得非常慢。
我想知道这两个 tensorflow 对象在用于训练神经网络时有什么区别? 最佳答案 Supervisor 即将被弃用,鼓励新用户使用 tf.train.FooSession 类 (来自 commen
我已经看到文档 tf.train.ExponentialMovingAverage 实现了这个公式: shadow_variable = decay * shadow_variable + (1 -
我发现在 Tensorflow 中有不同的方法来保存/恢复模型和变量。这些方式包括: tf.saved_model.simple_save tf.train.Checkpoint tf.train.S
查看两个带有参数的函数签名 tf.train.shuffle_batch_join( tensors_list, batch_size, capacity, min_after_dequeue, se
我使用 Binary data训练 DNN。 但是 tf.train.shuffle_batch 和 tf.train.batch 让我很困惑。 这是我的代码,我将对其进行一些测试。 首先Using_
正如文档/教程中提到的,我们可以调用 Estimator.fit()开始训练工作。 该方法所需的参数为 inputs这是对训练文件的 s3/file 引用。示例: estimator.fit({'tr
这个问题在这里已经有了答案: Split train data to train and validation by using tensorflow_datasets.load (TF 2.1) (
我知道这两个类都处理线程。根据文档,tf.train.Coordinator 协调一组线程的终止,而 tf.train.QueueRunner 保存队列的入队操作列表,每个操作都在一个线程中运行。 但
最近我读了this TensorFlow 中未记录特征的指南,因为我需要传递可变长度序列作为输入。但是,我发现 tf.train.SequenceExample 的协议(protocol)相对困惑(特
我是一名优秀的程序员,十分优秀!