Performing 1d convolution using a 2d kernel

33 views
Skip to first unread message

Loser

unread,
Mar 6, 2017, 10:40:25 PM3/6/17
to Keras-users
I a currently trying to perform a 1d convolution on a image using a 2d kernel. The 1d convolution should be performed across the X-axis of the image, the images are spectograms of audio files.  The image in which the convolution in performed is divided in to 13 section, each section centers around a center frequency, in which 13 different CNN network will perform 1d convolution to extract in total (x,13) feature points, and individually (x,1) feature points. x is given by the length of `data_output_train`

The kernel size is defined as such the center element will be the center frequency. 

This is how the data is currently stored:
 


   
def model(feature,train_input_data,
            train_output_data
,
            test_input_data
,
            test_output_data
):


           
#Feature number 0-12
            number_of_filters
= 1
           
#Debug stuff!
           
print feature
           
print center_freq[feature]
           
print center_freq[feature]*2
           
print int(center_freq[feature]*2)
           
print frequency_to_pixel_row(int(center_freq[feature]*2))
   
            col
= int(frequency_to_pixel_row(int(center_freq[feature]*2)))
           
#init Data containers
            data_train_input
= []
            data_test_input
= []
            data_train_output
= []
            data_test_output
= []
           
print "jghkjhk"
           
           
#Extract the desired section
           
for images in train_input_data:
               
if feature == 0:
                   
#print images.shape[0]
                    data_train_input
= images[images.shape[0] - int(center_freq[feature]*2):images.shape[0],:]
                   
#print data.shape
           
#Vstack so it can be used in keras
            data_train_input_vstack
= np.vstack(data_train_input)
           
           
#Extract the desired section
           
for images in test_input_data:
               
if feature == 0:
                   
#print images.shape[0]
                    data_test_input
= images[images.shape[0] - int(center_freq[feature]*2):images.shape[0],:]
                   
#print data.shape
            data_test_input_vstack
= np.vstack(data_test_input)
           
           
#Extract the desired output data
           
for rows in train_output_data:
               
#print rows.shape
                data_train_output
= rows[:,feature]
            data_train_output_vstack
= np.vstack(data_train_output)
   
           
#Extract the desired output data
           
for rows in test_output_data:
               
#print rows.shape
                data_test_output
= rows[:,feature]
            data_test_output_vstack
= np.vstack(data_test_output)

    
Now i need to define the network structure such that it performs the 1d convolution.. But how do i ensure it also does that? and performs the way i want it to do.. I guess i have to use convolution2d, but how do i fix it to only perform 1d convoulution?

Daπid

unread,
Mar 7, 2017, 4:30:40 AM3/7/17
to Loser, Keras-users
Why don't you use 1D convolution? It works on 2D arrays (time,
frequency), as a 2D convolution works on 3D arrays (x, y, colour).
> --
> You received this message because you are subscribed to the Google Groups
> "Keras-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to keras-users...@googlegroups.com.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/keras-users/bc249e31-6f5b-4221-9785-f8f01d81e7b9%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Daπid

unread,
Mar 7, 2017, 4:32:30 AM3/7/17
to Loser, Keras-users
And by that I meant the Convolution1D layer.
https://keras.io/layers/convolutional/#convolution1d

nof...@gmail.com

unread,
Mar 7, 2017, 6:34:08 AM3/7/17
to Keras-users, nof...@gmail.com
is it possible to it with a kernel?

Loser

unread,
Mar 7, 2017, 6:35:27 AM3/7/17
to Keras-users, nof...@gmail.com

a 2d kernel

nof...@gmail.com

unread,
Mar 7, 2017, 8:32:22 AM3/7/17
to Keras-users, nof...@gmail.com
Oh.. i do have (x,y,color).. 
Reply all
Reply to author
Forward
0 new messages