Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Demo_Inspection_Pipeline/inspectSection.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
65 lines (46 sloc)
1.8 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Import library of helper functions | |
import ImgPrcLib as IPL | |
# Import other required packages | |
import os | |
import tensorflow as tf | |
import numpy as np | |
# Constants | |
bitmask_directory = "./BitmaskImages" | |
network_model_filepath = "./NeuralNetwork/model.json" | |
network_weights_filepath = "./NeuralNetwork/model.h5" | |
def inspectSection(input_image, pose_id): | |
""" | |
inspectSection: Takes a raw image of airfoil, applies bitmasking and | |
cropping procedure based on the given pose_id, then evaluates the | |
image to determine if the part is OK/NOT-OK. | |
Parameters | |
---------- | |
input_image : MxNx3 uint8 array | |
Original RGB image directly from camera. | |
pose_id : int | |
Pose number that image was taken from | |
Returns | |
------- | |
result: boolean | |
True if image is OK, False if image is Not-OK | |
""" | |
# ----- Load Bitmask ----- | |
bitmask_filepath = os.path.join(bitmask_directory, 'POSE' + str(pose_id) + '.JPG') | |
bitmask = IPL.loadBitmaskImage(bitmask_filepath) | |
# ----- Apply Bitmask and Crop Image ----- | |
processed_image = IPL.processImage(input_image, bitmask) | |
#IPL.imshow(processed_image) | |
# ----- Resize Image ----- | |
downsampled_img = tf.image.resize_with_pad(processed_image, 224, 224) | |
# ----- Load NeuralNetwork ----- | |
print("Starting to load model") | |
network = IPL.loadNetwork(network_model_filepath, network_weights_filepath) | |
print("Model Loaded.") | |
# ----- Evaluate Image ----- | |
result = network(np.expand_dims(downsampled_img,0)) | |
# ----- Determine Class ----- | |
# argmax=0 --> NOT-OK | |
# argmax=1 --> OK | |
predicted_class = np.argmax(result) | |
result = (predicted_class == 1) | |
return result |