
I have a question regarding the code of the CNN that I am writing.

In the 1st attached picture, the dimensions of the input X_train in the original code were (number of examples “pictures”, number of pixels in x direction, number of pixels in ydirection, number of channels “red, blue and green”)
so they were (600, 64, 64, 3). 
In the 2nd attached picture, the dimensions of the input X_train in my implemented code were (number of examples , nx “number of nodes of the input”,1,1)
sp they were (3110, 15, 1, 1) 
What do you suggest? Because there is an error message regarding my dimensions.
Hey @Yahya_Ghareeb,
Welcome to the community. I am assuming that you are trying to run the model that we implemented in W1 A2 on just different inputs. If so, then the thing to note here is that the model that we have built in this assignment are built for images, which you would have known by now, after all, it’s a CNN (not getting into the exceptional usecases here).
Whereas, as you have mentioned you are trying to run it on inputs, each having a size of (15, 1, 1)
, which can be easily transformed into a 1D input. If your inputs are not images, then don’t you think, a standard feedforward neural network built out of dense layers, would be better suited rather than a CNN.
And if your inputs are images, then you either need to scale them to the size that is expected by the model, which in this case is (64, 64, 3)
, or you can modify the model to expect and work on (15, 1, 1)
images, which are essentially (15, 1)
greyscale images. I hope this helps you.
Cheers,
Elemento
I don’t understand your question. It looks like you are extending the exercise and trying to apply the happy_model
that was created there to a completely different dataset. Why are you doing that reshape to create X_train1
? What is the point of that? The happy_model
is designed and trained to handle input data in the form of 64 x 64 x 3 RGB images, so why would you expect that it would also be useful for processing input samples that are 15 x 1 x 1, whatever that data is?
Dear Elemento,
 In my master project, I have data from tables (not images).
 My supervisor asked me to reshape the data into (m number of examples in my data=3110 example, 3*5=15 cells for each example).
 So that the dimension of the input data is (m*15).
 the output is one output for each example so the dimension of the output data is (m*1).
 I have edited the code (FUNCTION: happyModel) to make accept a m11*15 input variable. However, it still gives me an error message.
 I have already implemented the feedforward neural network. Now, my supervisor asked me to try to implement CNN for my data, in order to compare the results between these 2 kinds.
 if I reshape the input into m11*15 and made 15 as the channels number, could I apply a filter on a 1x1 matrix?
Best regards,
Yahya
Dear Paulinpaloalto,

I am trying to use this code happy_model for my master project, I have different imput data which comes from tables (not images).

My supervisor asked me to reshape the data into (m number of examples in my data=3110 example, 3*5=15 cells for each example).

So that the dimension of the input data is (m*15).

the output is one output for each example so the dimension of the output data is (m*1).

I have already implemented the feedforward neural network. Now, my supervisor asked me to try to implement CNN for my data, in order to compare the results between these 2 kinds.

if I reshape the input into m11*15 and made 15 as the channels number, could I use a CNN for the data? and could I apply a filter on a 1x1 matrix?
Best regards,
Yahya
ConvNets are really intended for images, where the idea is that you can “step” a filter across and down an image, but that model doesn’t really apply to tabular data with 15 entries. The only way I can think of to make sense of applying a CNN to that case would be the 1 x 1 x 15 filters that you propose. I think that will end up being logically equivalent to a feed forward net, but you can try it and see.
I have tried to adjust the original code as the following,
1 adjust (FUNCTION: happyModel) to make expect an m1115 variable.
2 adjust my input data to make its dimension as m1115.
the code does not run, and it gave me the attached error message.
I don’t think that for your purposes here the ZeroPadding, BatchNorm and MaxPooling layers make any sense. Note the padding ends up giving you 3 x 3 x 15 output, which means that your actual data is literally only 1/3 of the output. How does that add any value?
Also note that you have shown us everything but the actual exception trace, which is what we would need in order to make sense of this error.
If you want to add value to the model, my suggestion would be to have more than 1 filter in your Conv2D layer. That’s where you will get the equivalent of lots of neurons if you were doing this with a Fully Connected network. How many layers did you use when you solved this with a Feed Forward net and how many neurons were there in each layer? Think about the total number of trainable weights you’ll have with the conv implementation. Just intuitively, it seems you’ll need as many trainable weights as in the FC case in order to get as good a result, right?
Notice that in your current implementation, you have a total of 26 trainable parameters: 16 in the Conv layer and 10 in the Dense layer at the end. How does that compare to your previous implementation?
Thanks for your feedback Paulinpaloalto,
 my FC network has 2 layers, (one hidden layer and an output layer).
 to be honest, in the FC network case, the network gives me error messages regarding calculating the cost function. I have several questions about that implementation and I will post another topic in the 1st course for that.
Best regards
How many neurons in each of the two layers? What did you use as the activation in the hidden layer? I guess we can wait for your thread in C1 about the cost function to learn about which you used. If you had trouble with the cost, did you get far enough to run the training and actually get any results to compare against your CNN implementation? What kind of accuracy numbers did you get?
in the input layer, the dimension is (m the number of examples 3110,15 value for each example)
in the hidden layer, 15 neurons.
in the output layer,1 neuron (there are 5 possible values in the output)
the activation function, for A1 Relue and for A2 Sigmoid.
I am using the code for two_layer_model in the C1W4 assignment ‘Deep Neural Network  Application’.
I have several error messages during calculating the cost I will share a new topic.
If there are 5 possible values for the output, then sigmoid is not going to work as the output activation. You’ll need softmax, I would think. That’s not been covered in Course 1.
ok, I did not know about that, I will try it tomorrow and see the result.
thank you for your feedback.