My Python version is 3.7 (Windows10, 64bit, tensorflow 2.0)
I implemented a program to detect eye-blink using opencv. Press F5 in the pycham to perform normal operation. I made exe file using pyinstaller. However, when I run with the generated exe file, an error occurs.
**............... tensorflow.python.framework.errors_impl.NotFoundError: C:\User\User Name\AppData\Local\Temp\_MEI401122\tensorflow\lite\experimental\microfrontend\python\ops\_audio_microfrontend_op.so not found
[40068] Failed to execute script test**
I've tried numerous ways and found a solution, but it's not working out.
Path on the error message is not on my PC.(Folder _MEI401122 does not exist)
On my PC, the _audio_microfrontend_op.so file is in the path of the picture below.
I have no idea. Please help me.
enter image description here
I add my source code and error content.
My project folder path is as follows.
Path: C:\Users\User Name\Downloads\eye_blink_detector-master
[My Error contents image]
enter image description here
[My source code]
# -*- coding: utf-8 -*-
import cv2, dlib
import numpy as np
from imutils import face_utils
from keras.models import load_model
from time import localtime, strftime
from datetime import datetime
import time
from tkinter import *
import tkinter.messagebox
root = Tk()
WELCOME_MSG = '''Welcome to this event.'''
WELCOME_DURATION = 2000
def welcome():
top = tkinter.Toplevel()
top.title('Welcome')
Message(top, text="카운트", padx=20, pady=20).pack()
top.after(WELCOME_DURATION, top.destroy)
IMG_SIZE = (34, 26)
#root.mainloop()
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor('shape_predictor_68_face_landmarks.dat')
model = load_model('models/2018_12_17_22_58_35.h5')
model.summary()
count = 0
count_eye_open = 0
f = open("d:/새파일.txt", 'a')
def crop_eye(img, eye_points):
x1, y1 = np.amin(eye_points, axis=0)
x2, y2 = np.amax(eye_points, axis=0)
cx, cy = (x1 + x2) / 2, (y1 + y2) / 2
w = (x2 - x1) * 1.2
h = w * IMG_SIZE[1] / IMG_SIZE[0]
margin_x, margin_y = w / 2, h / 2
min_x, min_y = int(cx - margin_x), int(cy - margin_y)
max_x, max_y = int(cx + margin_x), int(cy + margin_y)
eye_rect = np.rint([min_x, min_y, max_x, max_y]).astype(np.int)
eye_img = gray[eye_rect[1]:eye_rect[3], eye_rect[0]:eye_rect[2]]
return eye_img, eye_rect
# main
cap = cv2.VideoCapture(0) #'videos/2.mp4')
while cap.isOpened():
ret, img_ori = cap.read()
if not ret:
break
#윈도우 사이즈
img_ori = cv2.resize(img_ori, dsize=(0, 0), fx=1.0, fy=1.0)
img = img_ori.copy()
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = detector(gray)
dt = datetime.now()
for face in faces:
shapes = predictor(gray, face)
shapes = face_utils.shape_to_np(shapes)
eye_img_l, eye_rect_l = crop_eye(gray, eye_points=shapes[36:41]) #l_eye_poits = [36, 37, 38, 39, 40, 41] 원소스: [36,42]
eye_img_r, eye_rect_r = crop_eye(gray, eye_points=shapes[42:47]) #r_eye_points = [42, 43, 44, 45, 46, 47] 원소스: [42:48]
eye_img_l = cv2.resize(eye_img_l, dsize=IMG_SIZE)
eye_img_r = cv2.resize(eye_img_r, dsize=IMG_SIZE)
eye_img_r = cv2.flip(eye_img_r, flipCode=1)
cv2.imshow('l', eye_img_l)
cv2.imshow('r', eye_img_r)
eye_input_l = eye_img_l.copy().reshape((1, IMG_SIZE[1], IMG_SIZE[0], 1)).astype(np.float32) / 255.
eye_input_r = eye_img_r.copy().reshape((1, IMG_SIZE[1], IMG_SIZE[0], 1)).astype(np.float32) / 255.
pred_l = model.predict(eye_input_l)
pred_r = model.predict(eye_input_r)
# visualize
state_l = '%.2f' if pred_l > 0.1 else '-%.1f'
state_r = '%.2f' if pred_r > 0.1 else '-%.1f'
state_l = state_l % pred_l
state_r = state_r % pred_r
# Blink Count
if pred_l <= 0.1 and pred_r <= 0.1:
count_eye_open += 1
print("blinking, "+ str(dt.strftime('%Y-%m-%d %H:%M:%S.%f')))
cv2.rectangle(img, pt1=tuple(eye_rect_l[0:2]), pt2=tuple(eye_rect_l[2:4]), color=(255,255,255), thickness=2)
cv2.rectangle(img, pt1=tuple(eye_rect_r[0:2]), pt2=tuple(eye_rect_r[2:4]), color=(255,255,255), thickness=2)
cv2.putText(img, state_l, tuple(eye_rect_l[0:2]), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (255,255,255), 2)
cv2.putText(img, state_r, tuple(eye_rect_r[0:2]), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (255,255,255), 2)
cv2.putText(img, "eye blink: " + str(count_eye_open), (50, 50), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255))
cv2.putText(img, "Time: " + str(strftime("%S", localtime())), (50, 100), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255))
if str(strftime("%S", localtime())) == "00":
count += 1
if count == 1 and count_eye_open > 0:
print("Transfer Data...:" + str(count_eye_open))
f.write("Transfer Data...:" + str(count_eye_open) + "\n")
count_eye_open = 0
count = 0
else:
count = 0
time.sleep(0.12)
cv2.imshow('result', img)
if cv2.waitKey(1) == ord('q'):
f.close()
break
I was able to fix this error by manually specifying to copy the _audio_microfrontend_op.so file inside the spec file.
# -*- mode: python ; coding: utf-8 -*-
import os
import importlib
a = Analysis(
(...)
datas=[(os.path.join(os.path.dirname(importlib.import_module('tensorflow').__file__),
"lite/experimental/microfrontend/python/ops/_audio_microfrontend_op.so"),
"tensorflow/lite/experimental/microfrontend/python/ops/")],
(...)
)
For someone who is still confused in spec which is in directory, where is your original filename.py, add this in datas = []
(os.path.join(os.path.dirname(importlib.import_module('tensorflow').__file__),
"lite/experimental/microfrontend/python/ops/_audio_microfrontend_op.so"),
"tensorflow/lite/experimental/microfrontend/python/ops/")
Then put there import
import os
import importlib
Then run this to compile by the specs you changed.
pyinstaller filename.spec
Don't have enough rep to comment so I'll just post an answer that clarifies things. As Mieszko mentioned in his answer you need to manually specify to copy the _audio_microfrontend_op.so file.
To do so, open the directory that the original filename.py file is in. You'll find a file called filename.spec. Open this file in an editor and add the changes Mieszko specified:
# -*- mode: python ; coding: utf-8 -*-
import os
import importlib
a = Analysis(
(...)
datas=[(os.path.join(os.path.dirname(importlib.import_module('tensorflow').__file__),
"lite/experimental/microfrontend/python/ops/_audio_microfrontend_op.so"),
"tensorflow/lite/experimental/microfrontend/python/ops/")],
(...)
)
Once you've made those changes, save the file and then run pyinstaller again with the .spec file instead of the .py file
pyinstaller filename.spec
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With