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 2.4 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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=[16, 66, 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 = Activation("relu", name='relu1')(x)
  12. x = MaxPool2D(pool_size=2)(x)
  13. x = Conv2D(16, (3, 3), strides=1, padding='valid', name='conv2')(x)
  14. x = Activation("relu", name='relu2')(x)
  15. x = Conv2D(32, (3, 3), strides=1, padding='valid', name='conv3')(x)
  16. x = Activation("relu", name='relu3')(x)
  17. x = Flatten()(x)
  18. output = Dense(2,name = "dense")(x)
  19. output = Activation("relu", name='relu4')(output)
  20. model = Model([input], [output])
  21. return model
  22. model = getModel()
  23. model.load_weights("./model/model12.h5")
  24. def getmodel():
  25. return model
  26. def gettest_model():
  27. input = Input(shape=[16, 66, 3]) # change this shape to [None,None,3] to enable arbitraty shape input
  28. A = Conv2D(10, (3, 3), strides=1, padding='valid', name='conv1')(input)
  29. B = Activation("relu", name='relu1')(A)
  30. C = MaxPool2D(pool_size=2)(B)
  31. x = Conv2D(16, (3, 3), strides=1, padding='valid', name='conv2')(C)
  32. x = Activation("relu", name='relu2')(x)
  33. x = Conv2D(32, (3, 3), strides=1, padding='valid', name='conv3')(x)
  34. K = Activation("relu", name='relu3')(x)
  35. x = Flatten()(K)
  36. dense = Dense(2,name = "dense")(x)
  37. output = Activation("relu", name='relu4')(dense)
  38. x = Model([input], [output])
  39. x.load_weights("./model/model12.h5")
  40. ok = Model([input], [dense])
  41. for layer in ok.layers:
  42. print(layer)
  43. return ok
  44. def finemappingVertical(image):
  45. resized = cv2.resize(image,(66,16))
  46. resized = resized.astype(np.float)/255
  47. res= model.predict(np.array([resized]))[0]
  48. print("keras_predict",res)
  49. res =res*image.shape[1]
  50. res = res.astype(np.int)
  51. H,T = res
  52. H-=3
  53. #3 79.86
  54. #4 79.3
  55. #5 79.5
  56. #6 78.3
  57. #T
  58. #T+1 80.9
  59. #T+2 81.75
  60. #T+3 81.75
  61. if H<0:
  62. H=0
  63. T+=2;
  64. if T>= image.shape[1]-1:
  65. T= image.shape[1]-1
  66. image = image[0:35,H:T+2]
  67. image = cv2.resize(image, (int(136), int(36)))
  68. return image