daily pastebin goal
4%
SHARE
TWEET

Untitled

a guest Feb 19th, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from keras.layers import Dense, Dropout, Activation,Lambda,Input,LSTM
  2. from keras.layers import Conv1D, MaxPooling1D,Flatten,TimeDistributed,Reshape
  3. from keras.models import Model
  4. import keras
  5.  
  6.  
  7.  
  8.  
  9. # =============================================================================
  10.  
  11. #Spatial Part    
  12.  
  13. #conv1d for temperature.......>
  14.                                  #concatente
  15. #con1d for pressure    .......>
  16.  
  17. # =============================================================================
  18.  
  19. #  Conv1D Model 1
  20. pnnl_temp=Input(shape=(200,1))
  21. connv_temp1=Conv1D(filters=2,kernel_size=(10),strides=2,padding="valid" ,activation="relu")(pnnl_temp)
  22. conv_maxpooling1=MaxPooling1D(pool_size=3,strides=1)(connv_temp1)
  23. connv_temp2=Conv1D(filters=1,kernel_size=(10),strides=2,padding="valid" ,activation="relu")(conv_maxpooling1)
  24. conv_maxpooling2=MaxPooling1D(pool_size=2,strides=None)(connv_temp2)
  25. conv_maxpooling2_size=conv_maxpooling2.get_shape().as_list()[-1]*
  26.                                         conv_maxpooling2.get_shape().as_list()[-2] # find the number of elements in tensor
  27. conv_flatter_temp=Reshape((conv_maxpooling2_size,1))(conv_maxpooling2) #flatten layer returns (?,?)as dimension
  28.  
  29.  
  30. # Conv1D Model 2
  31. pnnl_pressure=Input(shape=(200,1))
  32. connv_pressure1=Conv1D(filters=2,kernel_size=(10),strides=2,padding="valid" ,activation="relu")(pnnl_pressure)
  33. conv_maxpooling_pressure1=MaxPooling1D(pool_size=3,strides=1)(connv_pressure1)
  34. connv_pressure2=Conv1D(filters=1,kernel_size=(10),strides=2,padding="valid" ,activation="relu")(conv_maxpooling_pressure1)
  35. conv_maxpooling_pressure2=MaxPooling1D(pool_size=2,strides=None)(connv_pressure2)
  36. conv_maxpooling2_size_pressure=conv_maxpooling_pressure2.get_shape().as_list()[-1]*
  37.                                         conv_maxpooling_pressure2.get_shape().as_list()[-2]
  38. conv_flatter_pressure=Reshape((conv_maxpooling2_size,1))(conv_maxpooling_pressure2)
  39.  
  40.  
  41. # Merge Conv1D 1&2
  42. output = keras.layers.concatenate([conv_flatter_pressure, conv_flatter_temp], axis=1)
  43. spatial_model=Model([pnnl_temp,pnnl_pressure],output)  
  44.  
  45.  
  46. #=============================================================================
  47. # temporal part
  48.  
  49. #x1.....>
  50.            #spatial_model ....> time distributed layer .....>lstm ......
  51. #x2....>
  52.  
  53.  
  54. # =============================================================================
  55.  
  56.  
  57. x1 = Input(shape=(224, 200, 1))
  58. x2 = Input(shape=(224, 200, 1))
  59. new_input=keras.layers.concatenate([x1,x2],axis=3)
  60. encoded_frame_sequence = TimeDistributed(Lambda(lambda x:spatial_model([x[:,:,0:1],x[:,:,1:]] )))(new_input)  # used lambda to allow multiple input for TimeDistributed
  61. new_encoded_frame_sequence=Reshape((224,42))(encoded_frame_sequence)
  62. lastm_1=LSTM(52)(new_encoded_frame_sequence)
  63. Temporal_model  =Model([x1,x2],lastm_1)
  64.      
  65. Layer (type)                    Output Shape         Param #     Connected to                    
  66. ==================================================================================================
  67. input_11 (InputLayer)           (None, 224, 200, 1)  0                                            
  68. __________________________________________________________________________________________________
  69. input_12 (InputLayer)           (None, 224, 200, 1)  0                                            
  70. __________________________________________________________________________________________________
  71. concatenate_6 (Concatenate)     (None, 224, 200, 2)  0           input_11[0][0]                  
  72.                                                                  input_12[0][0]                  
  73. __________________________________________________________________________________________________
  74. time_distributed_4 (TimeDistrib (None, 224, 42, 1)   0           concatenate_6[0][0]              
  75. __________________________________________________________________________________________________
  76. reshape_9 (Reshape)             (None, 224, 42)      0           time_distributed_4[0][0]        
  77. __________________________________________________________________________________________________
  78. lstm_4 (LSTM)                   (None, 52)           19760       reshape_9[0][0]                  
  79. ==================================================================================================
  80. Total params: 19,760
  81. Trainable params: 19,760
  82. Non-trainable params: 0
  83. __________________________________________________________________________________________________
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top