Message Boards Message Boards

GROUPS:

Binary image classifier

Posted 23 days ago
305 Views
|
11 Replies
|
0 Total Likes
|

Hi. I have a repository of images, which are classified in two categories, say A and B.

I tried to train a classifier with Classify, but this was obviously too heavy a task for it.

So I want to train a Neural Network to perform the task. I searched at the Wolfram NN Repository, but found no NN that could serve my purposes.

Can somebody guide me with respect to this?: a. If there is already an NN that acts as a binary image classifier, which one and how can I retrieve/use it?

b. Otherwise, how to build the NN myself?

Thanks and best. Francisco

11 Replies
Posted 22 days ago

Hi Francisco,

Can you explain what you mean by

but this was obviously too heavy a task for it.

Of course. It classified the photos very poorly. Basically, put everything into a single category. I tried other methods than the default (NaiveBayes for example), without success

Posted 22 days ago
  • What is the subject in the images?
  • Are the images very similar even though they are labeled differently?
  • How large is the training set?
  • Is there a large class imbalance in the training set?

Have you looked at the image classification examples in the Applications section of the documentation? It performs well on those images.

Could you post a few example images from each class?

Many thanks for your questions. The answers are the following:

a. What is the subject in the images? These are photos of people who belong to different non-state armed groups (guerrillas or militias)

b. Are the images very similar even though they are labeled differently? I frankly do not know. This is the very sense of trying to find a classifier that is able to tell them apart. My hypothesis is that they are different enough to be separated by a good classifier.

c. How large is the training set? I used 400 pics for each group --that means 800 in total. Maybe this is too small?

d. Is there a large class imbalance in the training set? No imbalance

I am attaching two examples (one for each group) of the type of photos I am dealing with (by the way, retrieved with WebImageSearch).

I will give a hard look at the documentation --thanks again

Attachment

Attachment

Attachments:

Many thanks for your questions. The answers are the following:

a. What is the subject in the images? These are photos of people who belong to different non-state armed groups (guerrillas or militias)

b. Are the images very similar even though they are labeled differently? I frankly do not know. This is the very sense of trying to find a classifier that is able to tell them apart. My hypothesis is that they are different enough to be separated by a good classifier.

c. How large is the training set? I used 400 pics for each group --that means 800 in total. Maybe this is too small?

d. Is there a large class imbalance in the training set? No imbalance

I am attaching two examples (one for each group) of the type of photos I am dealing with (by the way, retrieved with WebImageSearch).

I will give a hard look at the Classification function documentation, though I have already know it (I think) quite well --thanks again

Posted 22 days ago

I am confused by the response to question b.

I frankly do not know. This is the very sense of trying to find a classifier that is able to tell them apart. My hypothesis is that they are different enough to be separated by a good classifier.

In supervised learning the training data has to be accurately labeled (ground truth) as in the examples in the documentation. How were the images labeled?

Welcome to Wolfram Community! Please make sure you know the rules: https://wolfr.am/READ-1ST

Your post is too vague. Please "Edit" your post with all the answers of the replies you had here. Thank you.

They were labelled: "Guerrilla", "Militia" (or if you prefer "Class A", "Class B"). There is no problem or ambiguity related to the labels. Your question was how different were the photos from each other, so I answered to that question. Francisco

Posted 22 days ago

Something to try.

To get a random 80%, 10%, 10% split for training, validation and testing. images is the list of image -> class

{training, testing} = ResourceFunction["TrainTestSplit"][images];
{testing, validation} = ResourceFunction["TrainTestSplit"][testing, "TestSetSize" -> Scaled[0.5]]

classifier = Classify[training, ValidationSet -> validation, PerformanceGoal -> "Quality"]
cm = ClassifierMeasurements[classifier, testing]

cm["ConfusionMatrixPlot"]
cm /@ {"Accuracy", "Precision", "Recall", "F1Score"}

If the results are not satisfactory there are a lot of things to try to improve it. I would do that rather than building a DNN from scratch or even attempting transfer learning.

Creating a Neural Network class in Python is easy.

class NeuralNetwork:

def __init__(self, x, y):
    self.input      = x
    self.weights1   = np.random.rand(self.input.shape[1],4) 
    self.weights2   = np.random.rand(4,1)                 
    self.y          = y
    self.output     = np.zeros(y.shape)

https://towardsdatascience.com/how-to-build-your-own-neural-network-from-scratch-in-python-68998a08e4f6

There is no need to write a NN from scratch in WL. It has extensive built-in support for NN.

Writing a good image classifying NN from scratch is not an easy task.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract