SHARE
TWEET

Untitled

a guest Jun 20th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. kilograms_trees = tf.data.experimental.CsvDataset(
  2.         filenames='dataset/agrumeto.csv',
  3.         record_defaults=[tf.float32],
  4.         field_delim=",",
  5.         header=True)
  6.  
  7. kilo_train = kilograms_trees.take(35)
  8. kilo_test = kilograms_trees.skip(35)
  9.  
  10.  
  11. def create_conv_layer(input):
  12.     x = tf.keras.layers.Conv2D(32, (7, 7), activation='relu')(input)
  13.     x = tf.keras.layers.MaxPooling2D((2, 2), (2,2))(x)
  14.     x = tf.keras.Model(inputs=input, outputs=x)
  15.     return x
  16.  
  17. inputA = tf.keras.Input(shape=(size,size,3))
  18. inputB = tf.keras.Input(shape=(size,size,3))
  19. inputC = tf.keras.Input(shape=(size,size,3))
  20. inputD = tf.keras.Input(shape=(size,size,3))
  21.  
  22.  
  23. x = create_conv_layer(inputA)
  24. y = create_conv_layer(inputB)
  25. w = create_conv_layer(inputC)
  26. z = create_conv_layer(inputD)
  27.  
  28. # combine the output of the two branches
  29. combined = tf.keras.layers.concatenate([x.output, y.output, w.output, z.output])
  30.  
  31. layer_1 = tf.keras.layers.Conv2D(16, (3,3), activation="relu")(combined)
  32. layer_1 = tf.keras.layers.MaxPooling2D((2, 2))(layer_1)
  33.  
  34. layer_2 = tf.keras.layers.Conv2D(16, (3,3), activation="relu")(layer_1)
  35. layer_2 = tf.keras.layers.MaxPooling2D((2, 2), (2,2))(layer_2)
  36.  
  37. layer_3 = tf.keras.layers.Conv2D(32, (3,3), activation="relu")(layer_2)
  38. layer_3 = tf.keras.layers.MaxPooling2D((2, 2), (2,2))(layer_3)
  39.  
  40. layer_4 = tf.keras.layers.Conv2D(32, (3,3), activation="relu")(layer_3)
  41. layer_4 = tf.keras.layers.MaxPooling2D((2, 2), (2,2))(layer_4)
  42.  
  43. flatten = tf.keras.layers.Flatten()(layer_4)
  44. hidden1 = tf.keras.layers.Dense(10, activation='relu')(flatten)
  45. output = tf.keras.layers.Dense(1, activation='relu')(hidden1)
  46.  
  47. model = tf.keras.Model(inputs=[x.input, y.input, w.input, z.input], outputs=output)
  48.  
  49. print(model.summary())
  50.  
  51. model.compile(optimizer='adam',
  52.               loss="mean_absolute_percentage_error")
  53.  
  54. print("[INFO] training model...")
  55. model.fit([trainA, trainB, trainC, trainD], kilo_train, epochs=5, batch_size=4)
  56.  
  57. test_loss, test_acc = model.evaluate([testA, testB, testC, testD], kilo_test)
  58.  
  59. print(test_acc)
  60.      
  61. +-----------------------------------------------------------------------------+
  62. | NVIDIA-SMI 418.40.04    Driver Version: 418.40.04    CUDA Version: 10.1     |
  63. |-------------------------------+----------------------+----------------------+
  64. | GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
  65. | Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
  66. |===============================+======================+======================|
  67. |   0  GeForce GTX 1050    On   | 00000000:01:00.0 Off |                  N/A |
  68. | N/A   54C    P0    N/A /  N/A |   3830MiB /  4042MiB |      8%      Default |
  69. +-------------------------------+----------------------+----------------------+
  70.  
  71. +-----------------------------------------------------------------------------+
  72. | Processes:                                                       GPU Memory |
  73. |  GPU       PID   Type   Process name                             Usage      |
  74. |=============================================================================|
  75. |    0       909      C   ...ycharmProjects/agrumeto/venv/bin/python  3159MiB |
  76. |    0      1729      G   /usr/lib/xorg/Xorg                            27MiB |
  77. |    0      1870      G   /usr/bin/gnome-shell                          69MiB |
  78. |    0      6290      G   /usr/lib/xorg/Xorg                           273MiB |
  79. |    0      6420      G   /usr/bin/gnome-shell                         127MiB |
  80. |    0      6834      G   ...quest-channel-token=6261236721362009153    85MiB |
  81. |    0      8806      G   ...pycharm-professional/132/jre64/bin/java     2MiB |
  82. |    0     12830      G   ...-token=60E939FEF0A8E3D5C46B3D6911048536    31MiB |
  83. |    0     27478      G   ...-token=ECA4D3D9ADD8448674D34492E89E40E3    51MiB |
  84. +-----------------------------------------------------------------------------+
  85.      
  86. conv2d_7 (Conv2D)               (None, 14, 14, 32)   9248        max_pooling2d_6[0][0]            
  87. __________________________________________________________________________________________________
  88. max_pooling2d_7 (MaxPooling2D)  (None, 7, 7, 32)     0           conv2d_7[0][0]                  
  89. __________________________________________________________________________________________________
  90. flatten (Flatten)               (None, 1568)         0           max_pooling2d_7[0][0]            
  91. __________________________________________________________________________________________________
  92. dense (Dense)                   (None, 10)           15690       flatten[0][0]                    
  93. __________________________________________________________________________________________________
  94. dense_1 (Dense)                 (None, 1)            11          dense[0][0]                      
  95. ==================================================================================================
  96. Total params: 69,301
  97. Trainable params: 69,301
  98. Non-trainable params: 0
  99. __________________________________________________________________________________________________
  100. None
  101. [INFO] training model...
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