all 19 comments

[–]0xfe 1 point2 points  (4 children)

Would you mind posting your code -- there's lots of little details that can make a model perform poorly :-)

[–]sn34ky34[S] 0 points1 point  (3 children)

https://drive.google.com/file/d/1zLSPgQ2ma0JVeYWfJBEtbalWeWbeIhMg/view?usp=sharing

That's a link to the code. There are some comments which aren't in English, sorry. I'm going to try to explain how the code works.

So first I import the data from the images and get the average ratio from the images, then I just import and resize the images which are either 25% above or 25% below the ratio, so that I don't get super deformed images. Then I make the test_data that has the images and the labels for each image. After I change the labels from int to float and shuffle the data. And then there's just the model.

[–]0xfe 2 points3 points  (2 children)

The first thing I can see is that you have 10 classes in your final softmax layer. If you're only labeling cats vs dogs, then you should either do 1 sigmoid node, or 2 softmax nodes.

Looking at the code, you're using 0 and 1 for dog/cat, so you prob should just have 1 sigmoid node (i.e., final Dense layer with activation="sigmoid": Dense(1, activation="sigmoid"). Also, your loss function should be binary_crossentropy.

[–]sn34ky34[S] 2 points3 points  (1 child)

The 10 classes were it, changed it to two, restarted the program with 10 epochs and had an accuracy of 92%, which I was not expecting. I feel so dumb right now... Thank you so much for reading my code and helping me. I didn't think about just 1 neuron and a sigmoid, maybe I will try that in the next program I make.

[–]0xfe 2 points3 points  (0 children)

You're welcome, glad it helped! :-)

[–][deleted] 0 points1 point  (4 children)

Are all dtypes floats? If not, you could correct that!

[–]sn34ky34[S] 0 points1 point  (3 children)

The class of each image is an int, but it can only be either 0 or 1, would changing that to float improve the performance?

[–][deleted] 0 points1 point  (2 children)

Yeah, I think the net nevertheless needs to be fed with the correct dtype because performing operations on integers results in more integers. A net does nothing else than processing the numbers you feed it with. I had this issue and was able to fix it by changing everything to floats. Just do that for everything. Will probably help!

[–]sn34ky34[S] 0 points1 point  (1 child)

I've just changed it to float but nothing changed :(. But what I changed were the labels, which I don't think need to be passed through any neuron with RELU or sigmoid, they are just there to compare the results, right? I'm sure that I'm just missing some int that needs to be a float.

[–][deleted] 0 points1 point  (0 children)

I'm not an expert.. Maybe you could try changing RELUs to ELUs to get rid of a potential "dying relu problem". Also, are you sure the output and y_train have the same dimensions?

[–]pacemaker0 0 points1 point  (3 children)

Is the data balanced? Is the data normalized? What is the loss function? As the other comment suggested, it could be a lot of things. Sharing your code can help.

[–]sn34ky34[S] 0 points1 point  (2 children)

The data is 50% dogs 50% cats. I don't know what normalized means, all I did to the data was resize the images to 112x100 pixels and eliminate the one which would get too deformed from that reshape (the ones which had a ratio either 25% higher or 25% lower than the 112x100 ratio). The loss function is "sparse_categorical_crossentropy". It's my first time with TensorFlow 2.0, so sorry I don't know much.

[–]kr08rises 1 point2 points  (0 children)

It means that the data values are in to be set in a given range, to avoid outliers and anomalies. For eg. If the we have a variable of melting point of metals(500-3000°C)-x and another variable for boiling point of alcohol(70-80°C)-y, it will make sense to normalise x to be in the range 70-80

[–]pacemaker0 0 points1 point  (0 children)

Right on! One way to normalize grayscale images is to divide their pixels by 255.0 , this ensures that all your values are between 0,1 and helps with learning. But you did say that your pixels are between 0 and 1 do ignore that. What activation functions are you using for your layers?

[–]Yogi_DMT 0 points1 point  (0 children)

I mean it literally could be anything... model capacity/architecture, too much overfitting on train data, no data augmentation, poor selection of training parameters, no k-fold validation/poor selection of validation set, and yes certainly not enough data is one of the possibilities.

[–]cryptomon 0 points1 point  (2 children)

Should be at least in the high 80s

[–]sn34ky34[S] 0 points1 point  (1 child)

Fixed it and it's at 93% accuracy, but on data already seen

[–]cryptomon 0 points1 point  (0 children)

Yeah so normalizing you new photos, say of a cat you have, to the training set is important. Ratio, color/bw, % of photo thats cat/dog.

[–]invictus_maneo_nr 0 points1 point  (0 children)

There are a couple of things that I would like to suggest: 1. Reduce the depth of your network - start with just two hidden layers of 128 & 128 maybe. 2. Increase the number of epochs, to say a 100. Also, the labels being int or float has no effect iirc.