ทดลองใช้งาน ImageAI
TenserFlow คืออะไร TenserFlow นั้นเป็น deep learning library ของ Google โดยเป็น library ชนิดนึงที่ทาง Google พัฒนาขึ้นมา ให้ใช้งานกันได้แบบ Open source โดย TensorFlow นั้นจะสามารถทำงานทำงานประมวลผลสิ่งต่างๆแบบ Deep Learning สามารถประมวลผลข้อมูลจำนวนมาก ด้วยการจำลองเครือข่ายประสาทแบบเดียวกับในสมองของมนุษย์ เป็นวิธีการหนึ่งของการเรียนรู้ของเครื่องที่พยายามเรียนรู้วิธีการแทนข้อมูลอย่างมีประสิทธิภาพ
โดยวันนี้เราจะมาแนะนำ Library ตัวนึงที่นำ TenserFlow มาใช้งาน นั้นก็คือ ImageAI ซึ่ง ตัวของ library ตัวนี้นั้น จะทำงานโดยการจับภาพ ตัวของ ออฟเจค์ ต่างๆ บนรูปภาพแล้วบอกว่า สิ่งที่อยู่บนรูปนั้น มีอะไรบางโดยความแม่นยำที่จะทายถูกนั้น อยู่ที่ 60% ขึ้นไปกันเลยทีเดียว
เราจะมาสอนวิธีการใช้งาน ImageAI เบื้องต้นกัน โดยการที่จะใช้ ImageAI นั้นต้องมีความรู้ด้านภาษา Python มาก่อน
โดยขึ้นตอนแรก ทำการเปิด Editer ขึ้นมา ทำการ pip install ตามนี้นเลย
pip install tensorflow
pip install numpy
pip install scipy
pip install opencv-python
pip install pillow
pip install matplotlib
pip install h5py
pip install keras
pip install https://github.com/OlafenwaMoses/ImageAI/releases/2.0.2/imageai-2.0.2-py3-none-any.whl
จากนั้นสร้างไฟล์ Python ขึ้นมา แล้วใช้งาน code ตามนี้เลย
from imageai.Detection import ObjectDetection
import os
execution_path = os.getcwd()
detector = ObjectDetection()
detector.setModelTypeAsRetinaNet()
detector.setModelPath(os.path.join(execution_path,"resnet50_coco_best_v2.0.1.h5"))
detector.loadModel()
detections = detector.detectCustomObjectsFromImage(input_image=os.path.join(execution_path,
"thailand.jpg"), output_image_path=os.path.join(execution_path,"output image.jpg"))
for eachObject in detections :
print(eachObject["name"], ":" , eachObject["percentage_probability"])
1. จะเป็นชื่อของ Path ไฟล์รูปภาพที่เราต้องการเปิดขึ้นมา
2. จะเป็น ชื่อของ Path ไฟล์รูปภาพ ที่จะเซฟออกมาเมื่อเรา Run Code เสร็จแล้ว
เราจะใช้รูปภาพนี้ในการทดสอบ โดยนำ Path ของรูปภาพไปใส่ใน โค้ดให้เรียบร้อย แล้วกด Run Code
ผลลัพธ์ที่ได้
โดยจะมีเปอร์เซ็นแสดงที่รูปภาพด้วยว่า ความถูกต้องของการประมวลผล ประมาณกี่เปอร์เซ็น
เป็นไงกันบ้างกับการใช้ ImageAi ในหารจับรูปภาพซึ่งไม่ยากไม่ง่ายเลย ถ้าใครสนใจสามารถไปศึกษาต่อยอดได้เลย