FANN 错误 20:ann (4196752) 和数据 (1) 中的输出神经元数量与 Epochs 不匹配
FANN Error 20: The number of output neurons in the ann (4196752) and data (1) don't match Epochs
这是我从FANN网站上拿来的一个稍微修改过的示例程序。
我创建的等式是 c = pow(a,2) + b。
Train.c
#include "fann.h"
int main()
{
const unsigned int num_input = 2;
const unsigned int num_output = 1;
const unsigned int num_layers = 4;
const unsigned int num_neurons_hidden = 3;
const float desired_error = (const float) 0.001;
const unsigned int max_epochs = 500000;
const unsigned int epochs_between_reports = 1000;
struct fann *ann = fann_create_standard(num_layers, num_input,
num_neurons_hidden, num_output);
fann_set_activation_function_hidden(ann, FANN_SIGMOID_SYMMETRIC);
fann_set_activation_function_output(ann, FANN_SIGMOID_SYMMETRIC);
fann_train_on_file(ann, "sample.data", max_epochs,
epochs_between_reports, desired_error);
fann_save(ann, "sample.net");
fann_destroy(ann);
return 0;
}
Result.c
#include <stdio.h>
#include "floatfann.h"
int main()
{
fann_type *calc_out;
fann_type input[2];
struct fann *ann = fann_create_from_file("sample.net");
input[0] = 1;
input[1] = 1;
calc_out = fann_run(ann, input);
printf("sample test (%f,%f) -> %f\n", input[0], input[1], calc_out[0]);
fann_destroy(ann);
return 0;
}
我创建了自己的数据集
dataset.rb
f= File.open("sample.data","w")
f.write("100 2 1\n")
i=0
while i<100 do
first = rand(0..100)
second = rand(0..100)
third = first ** 2 + second
string1 = "#{first} #{second}\n"
string2 = "#{third}\n"
f.write(string1)
f.write(string2)
i=i+1
end
f.close
sample.data
100 2 1
95 27
9052
63 9
3978
38 53
1497
31 84
1045
28 56
840
95 80
9105
10 19
...
...
样本数据第一行给出了样本数、输入数和最后的输出数。
但是我收到一个错误
FANN Error 20: The number of output neurons in the ann (4196752) and data (1) don't match Epochs
这里有什么问题?它如何计算 4196752
个神经元?
在这里,使用 fann_create_standard,函数签名是 fann_create_standard(num_layers, layer1_size, layer2_size, layer3_size...)
,而您正在尝试以不同的方式使用它:
struct fann *ann = fann_create_standard(num_layers, num_input,
num_neurons_hidden, num_output);
你构建了一个4层的网络,但只提供了3层的数据。输出层的4196752个神经元很可能来自未定义的值。
这是我从FANN网站上拿来的一个稍微修改过的示例程序。
我创建的等式是 c = pow(a,2) + b。
Train.c
#include "fann.h"
int main()
{
const unsigned int num_input = 2;
const unsigned int num_output = 1;
const unsigned int num_layers = 4;
const unsigned int num_neurons_hidden = 3;
const float desired_error = (const float) 0.001;
const unsigned int max_epochs = 500000;
const unsigned int epochs_between_reports = 1000;
struct fann *ann = fann_create_standard(num_layers, num_input,
num_neurons_hidden, num_output);
fann_set_activation_function_hidden(ann, FANN_SIGMOID_SYMMETRIC);
fann_set_activation_function_output(ann, FANN_SIGMOID_SYMMETRIC);
fann_train_on_file(ann, "sample.data", max_epochs,
epochs_between_reports, desired_error);
fann_save(ann, "sample.net");
fann_destroy(ann);
return 0;
}
Result.c
#include <stdio.h>
#include "floatfann.h"
int main()
{
fann_type *calc_out;
fann_type input[2];
struct fann *ann = fann_create_from_file("sample.net");
input[0] = 1;
input[1] = 1;
calc_out = fann_run(ann, input);
printf("sample test (%f,%f) -> %f\n", input[0], input[1], calc_out[0]);
fann_destroy(ann);
return 0;
}
我创建了自己的数据集
dataset.rb
f= File.open("sample.data","w")
f.write("100 2 1\n")
i=0
while i<100 do
first = rand(0..100)
second = rand(0..100)
third = first ** 2 + second
string1 = "#{first} #{second}\n"
string2 = "#{third}\n"
f.write(string1)
f.write(string2)
i=i+1
end
f.close
sample.data
100 2 1
95 27
9052
63 9
3978
38 53
1497
31 84
1045
28 56
840
95 80
9105
10 19
...
...
样本数据第一行给出了样本数、输入数和最后的输出数。
但是我收到一个错误
FANN Error 20: The number of output neurons in the ann (4196752) and data (1) don't match Epochs
这里有什么问题?它如何计算 4196752
个神经元?
在这里,使用 fann_create_standard,函数签名是 fann_create_standard(num_layers, layer1_size, layer2_size, layer3_size...)
,而您正在尝试以不同的方式使用它:
struct fann *ann = fann_create_standard(num_layers, num_input,
num_neurons_hidden, num_output);
你构建了一个4层的网络,但只提供了3层的数据。输出层的4196752个神经元很可能来自未定义的值。