Answer the question
In order to leave comments, you need to log in
Where is the error in training a neural network to distinguish images?
Hello, I need the network to distinguish whether there is an object in the image or not.
More precisely, it is necessary to determine whether there is an ulcer in the photo of the mucous membrane or not
. The database was collected 50 photos - yes, 50 photos - no
resize / 0 - no; resize/1-yes
All images are black and white and 300x500 in size
Example of images with
and without an ulcer
Here is the training code:
$j = 0;
$my_example = array();
for ( $i = 0; $i < 2; $i++ )
{
$d = dir("resize/$i");
while($entry = $d->read())
{
if ( preg_match("/jpg/", $entry) )
{
$im = imagecreatefromjpeg("black/$i/$entry");//Подгружаем картинку
$cur_array = array(); //Создаем массив в котором в одну строку будут собраны номера цветов каждого пикселя
$cnt = 0;
for($y=0; $y<300; $y++)
{
for($x=0; $x < 500; $x++)
{
$rgb = imagecolorat($im, $x, $y) / 16777215;//Приводим к виду "меньше ноля"
$cur_array[$cnt] = $rgb;
$cnt++;
}
}
imagedestroy($im);
$my_example[$j] = array($cur_array, array($i));//Собираем массив, с которого будем обучать
$j++;
}
}
}
$num_input = 150000;//нейронов на вход 500x300
$num_output = 1;//нейронов на выход
$num_layers = 3;
$num_neurons_hidden = 100;
$desired_error = 0.000001;
$max_epochs = 5000000;
$epochs_between_reports = 10;
//И вот собственно само обучение
$ocr_ann = fann_create_standard($num_layers, $num_input, $num_neurons_hidden, $num_output);
if ($ocr_ann) {
echo 'Training OCR... ';
fann_set_activation_function_hidden($ocr_ann, FANN_SIGMOID_SYMMETRIC);
fann_set_activation_function_output($ocr_ann, FANN_SIGMOID_SYMMETRIC);
for ($i = 1; $i <= 150000; $i++)
{
$input[] = $i;
}
$desired_output = array( 1 );
var_dump( fann_train( $ocr_ann, $input, $desired_output ) );
fann_save($ocr_ann, dirname(__FILE__) . "/ocr_float3.net");
}
echo "Hello!";
$j = 0;
$my_example = array();
$im = imagecreatefromjpeg("black/0/1.jpg");
$cur_array = array();
$cnt = 0;
for($y=0; $y<300; $y++)
{
for($x=0; $x < 500; $x++)
{
$rgb = imagecolorat($im, $x, $y) / 16777215;
$cur_array[$cnt] = $rgb;
$cnt++;
}
}
imagedestroy($im);
echo "Hello!";
$train_file = (dirname(__FILE__) . '/ocr_float3.net');
$ocr_ann = fann_create_from_file($train_file);
$calc_out = fann_run($ocr_ann, $cur_array);
echo "Hello!";
var_dump($calc_out);
Answer the question
In order to leave comments, you need to log in
ab-log.ru/smart-house/video_camera_security/face-d...
1. First you need to learn how to determine the zone (crop-zone) where an ulcer is possible and bring all images to a single unified form (it is necessary to reduce possible NS errors by next paragraph).
2. Based on the values of the weights of the National Assembly, calculated on the basis of the displayed pixels for each photo, you need to CLASSIFY the sets into 2 classes (as I understand that you need it so much): "with an ulcer" and "without an ulcer".
The code you presented is a special case for prepared images (i.e. starting from step 2). Also, it is necessary to increase the number of hidden layers to achieve more detailed and accurate clustering.
PS: Yes, and one more thing... If you want to have a ready-made working code written here, you are mistaken: this is for freelance.
First, a multilayer perceptron is not a suitable architecture, look towards convolutional networks.
Secondly, 100 photos may not be enough for learning from scratch, especially without augmentation.
Third, the sigmoid is a poor choice of activation function.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question