You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

finemapping_vertical.py 1.3 kB

7 years ago
7 years ago
12345678910111213141516171819202122232425262728293031323334353637
  1. #coding=utf-8
  2. from keras.layers import Conv2D, Input,MaxPool2D, Reshape,Activation,Flatten, Dense
  3. from keras.models import Model, Sequential
  4. from keras.layers.advanced_activations import PReLU
  5. from keras.optimizers import adam
  6. import numpy as np
  7. import cv2
  8. def getModel():
  9. input = Input(shape=[12, 50, 3]) # change this shape to [None,None,3] to enable arbitraty shape input
  10. x = Conv2D(10, (3, 3), strides=1, padding='valid', name='conv1')(input)
  11. x = PReLU(shared_axes=[1, 2], name='prelu1')(x)
  12. x = MaxPool2D(pool_size=2)(x)
  13. x = Conv2D(16, (3, 3), strides=1, padding='valid', name='conv2')(x)
  14. x = PReLU(shared_axes=[1, 2], name='prelu2')(x)
  15. x = Conv2D(32, (3, 3), strides=1, padding='valid', name='conv3')(x)
  16. x = PReLU(shared_axes=[1, 2], name='prelu3')(x)
  17. x = Flatten()(x)
  18. output = Dense(2)(x)
  19. output = PReLU(name='prelu4')(output)
  20. model = Model([input], [output])
  21. return model
  22. model = getModel()
  23. model.load_weights("./model/model12.h5")
  24. def finemappingVertical(image):
  25. resized = cv2.resize(image,(50,12))
  26. resized = resized.astype(np.float)/255
  27. res= model.predict(np.array([resized]))[0]
  28. res =res*image.shape[1]
  29. res = res.astype(np.int)
  30. image = image[0:35,res[0]+4:res[1]]
  31. image = cv2.resize(image, (int(136), int(36)))
  32. return image