Commit 12406f2c authored by dasharatha.vamshi's avatar dasharatha.vamshi

changes

parent 745cbdb6
...@@ -56,6 +56,7 @@ class Welspun_Classifier(ModelWrapper): ...@@ -56,6 +56,7 @@ class Welspun_Classifier(ModelWrapper):
self.defect_type = "" self.defect_type = ""
self.frame_skip_count = 25 self.frame_skip_count = 25
self.counter = 0 self.counter = 0
self.k = 0
def _pre_process(self, x): def _pre_process(self, x):
""" """
...@@ -188,167 +189,170 @@ class Welspun_Classifier(ModelWrapper): ...@@ -188,167 +189,170 @@ class Welspun_Classifier(ModelWrapper):
return exp_vec / np.sum(exp_vec) return exp_vec / np.sum(exp_vec)
def process_frame(self, frame): def process_frame(self, frame):
starttime = time.time() if self.k % 25 == 0:
vino_frame = frame.copy() self.k = self.k + 1
# vino_frame = vino_frame[20:600,150:650] starttime = time.time()
vino_frame = vino_frame[5: 600, 70: 650] vino_frame = frame.copy()
images = np.ndarray(shape=(self.n, self.c, self.h, self.w)) # vino_frame = vino_frame[20:600,150:650]
images_hw = [] vino_frame = vino_frame[5: 600, 70: 650]
for i in range(self.n): images = np.ndarray(shape=(self.n, self.c, self.h, self.w))
image = vino_frame images_hw = []
ih, iw = image.shape[:-1] for i in range(self.n):
images_hw.append((ih, iw)) image = vino_frame
ih, iw = image.shape[:-1]
images_hw.append((ih, iw))
if (ih, iw) != (self.h, self.w): if (ih, iw) != (self.h, self.w):
# log.warning("Image {} is resized from {} to {}".format(img, image.shape[:-1], (h, w))) # log.warning("Image {} is resized from {} to {}".format(img, image.shape[:-1], (h, w)))
image = cv2.resize(image, (self.w, self.h)) image = cv2.resize(image, (self.w, self.h))
image = self.normalize(image) image = self.normalize(image)
# log.warning("Image {} is resized from {} to {}".format(args.input[i], image.shape[:-1], (h, w))) # log.warning("Image {} is resized from {} to {}".format(args.input[i], image.shape[:-1], (h, w)))
image = image.transpose((2, 0, 1)) # Change data layout from HWC to CHW image = image.transpose((2, 0, 1)) # Change data layout from HWC to CHW
images[i] = image images[i] = image
# log.info("Batch size is {}".format(n)) # log.info("Batch size is {}".format(n))
# #
# log.info("Starting inference in synchronous mode") # log.info("Starting inference in synchronous mode")
start = time.time() start = time.time()
res = self.exec_net.infer(inputs={self.input_blob: images}) res = self.exec_net.infer(inputs={self.input_blob: images})
print(f"Inference time: {time.time() - start}") print(f"Inference time: {time.time() - start}")
# Processing output blob # Processing output blob
# log.info("Processing output blob") # log.info("Processing output blob")
res = res[self.out_blob] res = res[self.out_blob]
prob = self.softmax_function(res[0]) prob = self.softmax_function(res[0])
x = [] x = []
x.append(prob[0]) x.append(prob[0])
x.append(prob[1]) x.append(prob[1])
x.append(prob[2]) x.append(prob[2])
x.append(prob[3]) x.append(prob[3])
x.append(prob[4]) x.append(prob[4])
a = x.index(max(x)) a = x.index(max(x))
# print(type(prob)) # print(type(prob))
# if self.counter%1 == 0: # if self.counter%1 == 0:
self.counter = self.counter + 1 self.counter = self.counter + 1
if a == 1 and x[1] > 0.95: if a == 1 and x[1] > 0.95:
if self.defect_type == 'Mix': if self.defect_type == 'Mix':
cv2.putText(frame, text="Mix Color Defect Detected", org=(50, 50), cv2.putText(frame, text="Mix Color Defect Detected", org=(50, 50),
color=(0, 0, 255), color=(0, 0, 255),
thickness=2, thickness=2,
fontScale=1, fontFace=cv2.LINE_AA) fontScale=1, fontFace=cv2.LINE_AA)
# pass # pass
else: else:
self.defect_type = 'Mix' self.defect_type = 'Mix'
resized_frame = cv2.resize(frame, (64, 64)) resized_frame = cv2.resize(frame, (64, 64))
cv2.putText(frame, text="Mix Color Defect Detected", org=(50, 50), cv2.putText(frame, text="Mix Color Defect Detected", org=(50, 50),
color=(0, 0, 255), color=(0, 0, 255),
thickness=2, thickness=2,
fontScale=1, fontFace=cv2.LINE_AA) fontScale=1, fontFace=cv2.LINE_AA)
self.send_payload("Mix Color Detected", resized_frame, "Mix Color " + str(prob[0]), "#472020", self.send_payload("Mix Color Detected", resized_frame, "Mix Color " + str(prob[0]), "#472020",
"#ed2020", "#ed2020",
"sound_1") "sound_1")
logger.info(f"Probability: {prob}") logger.info(f"Probability: {prob}")
# if self.counter % 25 == 0:
# self.send_payload("Mix Color Detected", resized_frame, "Mix Color " + str(prob[0]), "#472020",
# "#ed2020",
# "sound_1")
# logger.info(f"Probability: {prob}")
# self.counter = 0
elif a == 3 and x[3] > 0.95:
if self.defect_type == 'Short':
cv2.putText(frame, text="Short Defect Detected", org=(50, 50),
color=(0, 0, 255),
thickness=2,
fontScale=1, fontFace=cv2.LINE_AA)
# pass
else:
self.defect_type = 'Short'
resized_frame = cv2.resize(frame, (64, 64))
cv2.putText(frame, text="Short Defect Detected", org=(50, 50),
color=(0, 0, 255),
thickness=2,
fontScale=1, fontFace=cv2.LINE_AA)
self.send_payload("Short Tile Detected", resized_frame, "Short Tile " + str(prob[2]), "#472020",
"#ed2020",
"sound_1")
logger.info(f"Probability: {prob}")
# if self.counter % 25 == 0: # if self.counter % 25 == 0:
# self.send_payload("Mix Color Detected", resized_frame, "Mix Color " + str(prob[0]), "#472020", # self.send_payload("Short Tile Detected", resized_frame, "Short Tile " + str(prob[2]), "#472020",
# "#ed2020", # "#ed2020",
# "sound_1") # "sound_1")
# logger.info(f"Probability: {prob}") # logger.info(f"Probability: {prob}")
# self.counter = 0 # self.counter = 0
elif a == 3 and x[3] > 0.95: elif a == 4 and x[4] > 0.95:
if self.defect_type == 'Short': if self.defect_type == 'Split':
cv2.putText(frame, text="Short Defect Detected", org=(50, 50), cv2.putText(frame, text="Split Defect Detected", org=(50, 50),
color=(0, 0, 255), color=(0, 0, 255),
thickness=2, thickness=2,
fontScale=1, fontFace=cv2.LINE_AA) fontScale=1, fontFace=cv2.LINE_AA)
# pass # pass
else: else:
self.defect_type = 'Short' self.defect_type = 'Split'
resized_frame = cv2.resize(frame, (64, 64)) resized_frame = cv2.resize(frame, (64, 64))
cv2.putText(frame, text="Short Defect Detected", org=(50, 50), cv2.putText(frame, text="Split Defect Detected", org=(50, 50),
color=(0, 0, 255), color=(0, 0, 255),
thickness=2, thickness=2,
fontScale=1, fontFace=cv2.LINE_AA) fontScale=1, fontFace=cv2.LINE_AA)
self.send_payload("Short Tile Detected", resized_frame, "Short Tile " + str(prob[2]), "#472020", self.send_payload("Split Defect Detected", resized_frame, "Split " + str(prob[3]), "#472020",
"#ed2020", "#ed2020",
"sound_1") "sound_1")
logger.info(f"Probability: {prob}") logger.info(f"Probability: {prob}")
# if self.counter % 25 == 0: # if self.counter % 25 == 0:
# self.send_payload("Short Tile Detected", resized_frame, "Short Tile " + str(prob[2]), "#472020", # self.send_payload("Split Defect Detected", resized_frame, "Split " + str(prob[3]), "#472020", "#ed2020",
# "#ed2020", # "sound_1")
# "sound_1") # logger.info(f"Probability: {prob}")
# logger.info(f"Probability: {prob}") # self.counter = 0
# self.counter = 0 elif a == 0 and x[0] > 0.95:
elif a == 4 and x[4] > 0.95: if self.defect_type == 'good':
if self.defect_type == 'Split': cv2.putText(frame, text="No Defect", org=(50, 50),
cv2.putText(frame, text="Split Defect Detected", org=(50, 50), color=(0, 0, 255),
color=(0, 0, 255), thickness=2,
thickness=2, fontScale=1, fontFace=cv2.LINE_AA)
fontScale=1, fontFace=cv2.LINE_AA) # pass
# pass else:
else: self.defect_type = 'good'
self.defect_type = 'Split' resized_frame = cv2.resize(frame, (64, 64))
resized_frame = cv2.resize(frame, (64, 64)) cv2.putText(frame, text="No Defect", org=(50, 50),
cv2.putText(frame, text="Split Defect Detected", org=(50, 50), color=(0, 0, 255),
color=(0, 0, 255), thickness=2,
thickness=2, fontScale=1, fontFace=cv2.LINE_AA)
fontScale=1, fontFace=cv2.LINE_AA) self.send_payload("No Defect", resized_frame, "no defect " + str(prob[3]), "#044b04", "#24dc24",
self.send_payload("Split Defect Detected", resized_frame, "Split " + str(prob[3]), "#472020", "#ed2020", "sound_1")
"sound_1") logger.info(f"Probability: {prob}")
logger.info(f"Probability: {prob}") # if self.counter % 25 == 0:
# if self.counter % 25 == 0: # self.send_payload("Split Defect Detected", resized_frame, "Split " + str(prob[3]), "#472020", "#ed2020",
# self.send_payload("Split Defect Detected", resized_frame, "Split " + str(prob[3]), "#472020", "#ed2020", # "sound_1")
# "sound_1") # logger.info(f"Probability: {prob}")
# logger.info(f"Probability: {prob}") # self.counter = 0
# self.counter = 0 elif a == 2:
elif a == 0 and x[0] > 0.95: pass
if self.defect_type == 'good':
cv2.putText(frame, text="No Defect", org=(50, 50),
color=(0, 0, 255),
thickness=2,
fontScale=1, fontFace=cv2.LINE_AA)
# pass
else:
self.defect_type = 'good'
resized_frame = cv2.resize(frame, (64, 64))
cv2.putText(frame, text="No Defect", org=(50, 50),
color=(0, 0, 255),
thickness=2,
fontScale=1, fontFace=cv2.LINE_AA)
self.send_payload("No Defect", resized_frame, "no defect " + str(prob[3]), "#044b04", "#24dc24",
"sound_1")
logger.info(f"Probability: {prob}")
# if self.counter % 25 == 0:
# self.send_payload("Split Defect Detected", resized_frame, "Split " + str(prob[3]), "#472020", "#ed2020",
# "sound_1")
# logger.info(f"Probability: {prob}")
# self.counter = 0
elif a == 2:
pass
# else: # else:
# logger.info("enter else loop") # logger.info("enter else loop")
# if sum(sum(sum(frame))) == 0: # if sum(sum(sum(frame))) == 0:
# pass # pass
# else: # else:
# resized_frame = cv2.resize(frame, (64, 64)) # resized_frame = cv2.resize(frame, (64, 64))
# cv2.putText(frame, text="No Defect", org=(50, 50), # cv2.putText(frame, text="No Defect", org=(50, 50),
# color=(0, 0, 255), # color=(0, 0, 255),
# thickness=2, # thickness=2,
# fontScale=1, fontFace=cv2.LINE_AA) # fontScale=1, fontFace=cv2.LINE_AA)
# #
# if self.counter % 25 == 0: # if self.counter % 25 == 0:
# self.send_payload("No Defect", resized_frame, "No Defect ", "#044b04", "#24dc24", "sound_1") # self.send_payload("No Defect", resized_frame, "No Defect ", "#044b04", "#24dc24", "sound_1")
# logger.info(f"Probability: {prob}") # logger.info(f"Probability: {prob}")
# self.counter = 0 # self.counter = 0
# if prob[0] > 0.9: # if prob[0] > 0.9:
# # print("prob--->",prob[0]) # # print("prob--->",prob[0])
# cv2.putText(frame, text="Stitch Detected with Probability :" + str(prob[0]), org=(50, 50), # cv2.putText(frame, text="Stitch Detected with Probability :" + str(prob[0]), org=(50, 50),
# color=(255, 255, 255), # color=(255, 255, 255),
# thickness=1, # thickness=1,
# fontScale=1, fontFace=cv2.LINE_AA) # fontScale=1, fontFace=cv2.LINE_AA)
# self.send_payload("Stitch Detected", frame, "Stitch " + str(prob[0]), "#472020", "#ed2020", "sound_1") # self.send_payload("Stitch Detected", frame, "Stitch " + str(prob[0]), "#472020", "#ed2020", "sound_1")
# logger.info(f"Probability: {prob}") # logger.info(f"Probability: {prob}")
# self.counter= self.counter + 1 # self.counter= self.counter + 1
print("total time taken to process-------------> ", str(time.time() - starttime)) print("total time taken to process-------------> ", str(time.time() - starttime))
# logger.info(f"total time taken to process----------------- {time.time()-starttime}") # logger.info(f"total time taken to process----------------- {time.time()-starttime}")
# cv2.imshow('res', frame) # cv2.imshow('res', frame)
return frame return frame
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment