Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1.  
  2. import cv2, glob
  3. import tensorflow as tf
  4. import matplotlib.pyplot as plt
  5. import numpy as np
  6. import os
  7. import sqlalchemy as db
  8. from sqlalchemy.sql import select
  9.  
  10.  
  11. engine = db.create_engine('sqlite:///drawpad.db')
  12. connection = engine.connect()
  13. metadata = db.MetaData()
  14. drawpad = db.Table('images',metadata,autoload=True,autoload_with = engine)
  15. s = select([drawpad]).order_by(db.desc(drawpad.columns.img_url.label('img_url') )).limit(1)
  16. result = connection.execute(s)
  17. row = result.fetchone()
  18. # print(row['img_url'])
  19.  
  20. x = row['img_url']
  21. ImgAddress = x[15:]
  22.  
  23.  
  24.  
  25. print(ImgAddress)
  26.  
  27. testing ="C:/Canvas/static/dataset/" + str(ImgAddress)
  28. print(testing)
  29.  
  30.  
  31. images=glob.glob(testing)
  32.  
  33. for image in images:
  34. img = cv2.imread(image,0)
  35.  
  36. re=cv2.resize(img, (int(img.shape[1]/25), int(img.shape[0]/18.75)), interpolation = cv2.INTER_AREA)
  37.  
  38. cv2.imshow("cek",re)
  39.  
  40. cv2.waitKey(500)
  41. cv2.destroyAllWindows()
  42.  
  43. image = "testing.jpg"
  44.  
  45. cv2.imwrite("resize/"+image, re)
  46.  
  47.  
  48.  
  49.  
  50. CATEGORIES = ["Baju", "Celana", "Kupukupu", "Kursi", "Sepeda"]
  51.  
  52. def data(filepath):
  53. IMG_SIZE = 32
  54. img_array = cv2.imread(filepath, cv2.IMREAD_GRAYSCALE)
  55. new_array = cv2.resize(img_array, (IMG_SIZE, IMG_SIZE))
  56. plt.imshow(img_array, cmap = "gray")
  57. plt.show()
  58. return new_array.reshape(-1, IMG_SIZE, IMG_SIZE, 1)
  59.  
  60.  
  61. model = tf.keras.models.load_model("maxpooling_train_data.model")
  62. prediction = model.predict([data("C:/Canvas/resize/testing.jpg")])
  63. J = CATEGORIES[np.argmax(prediction)]
  64. print(J)
  65.  
  66.  
  67. model = tf.keras.models.load_model("avgpooling_train_data.model")
  68. prediction = model.predict([data("C:/Canvas/resize/testing.jpg")])
  69. K = CATEGORIES[np.argmax(prediction)]
  70. print(K)
  71.  
  72.  
  73.  
  74. coba = db.Table('Hasil',metadata,autoload=True,autoload_with = engine)
  75. ins = coba.insert()
  76. ins = coba.insert().values(img_url=x, hasil=J)
  77. str(ins)
  78. ins.compile().params
  79. tampil=connection.execute(ins)
  80.  
  81.  
  82. coba = db.Table('HasilMax',metadata,autoload=True,autoload_with = engine)
  83. ins = coba.insert()
  84. ins = coba.insert().values(img_url=x, hasilMax= K)
  85. str(ins)
  86. ins.compile().params
  87. tampil=connection.execute(ins)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement