SHARE
TWEET

Untitled

a guest Jun 16th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ##imports
  2. from keras.applications.resnet50 import ResNet50
  3. from keras.layers import Input
  4. from keras.layers import Lambda
  5. from keras.models import Model
  6. from keras.optimizers import Adam
  7. import keras
  8. import keras.backend as K
  9. import numpy as np
  10.  
  11. #pop off the input
  12. res = ResNet50(weights=None,include_top=True,classes=2)
  13. res.layers.pop(0)
  14.  
  15. #add two inputs
  16. auxinput= Input(batch_shape=(None,224,224,1), name='aux_input')
  17. main_input = Input(batch_shape=(None,224,224,3), name='main_input')
  18.  
  19. #use a lambda functon to return just our main input (avoids errors from out auxilary input not being used in resnet50 component)
  20. l_output = Lambda(lambda x: x[0])([main_input, auxinput])
  21.  
  22. #feed our main layer to resnet50
  23. data_passed_thru = res(l_output)
  24.  
  25. #assemble the model with our two inputs, and output
  26. mymodel = Model(inputs=[main_input, auxinput], outputs=[data_passed_thru])
  27. mymodel.compile(optimizer=Adam(lr=0.001), loss= keras.losses.poisson, metrics=[ 'accuracy'])
  28. print("my model summary:")
  29. mymodel.summary()
  30.  
  31. ##generate some fake data for testing
  32. fake_aux= np.zeros((224,224))
  33. fake_aux=fake_aux[None,...]
  34. fake_aux=fake_aux[...,None]
  35. print('fake aux input shape:', fake_aux.shape)
  36. fake_main= np.zeros((224,224,3))
  37. fake_main=fake_main[None,...]
  38. print('fake main input shape:', fake_main.shape)
  39.  
  40. #check our model inputs and target layer
  41. print("inputs:", mymodel.input)
  42. print("layer outout I'm trying to extract:", mymodel.layers[-1].layers[-6])
  43.  
  44. #create function to feed inputs, get our desired layer outputs
  45. get_output_func = K.function( mymodel.input ,  [mymodel.layers[-1].layers[-6].output])
  46.  
  47. ##this is the line that fails
  48. X= [fake_main,fake_aux]
  49. preds=get_output_func(X)
  50.      
  51. InvalidArgumentError: You must feed a value for placeholder tensor 'input_1' with dtype float and shape [?,224,224,3]
  52.      [[{{node input_1}}]]
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top