Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 16743

face_recognition and pytorch module conflict

$
0
0
import os, pathlibimport streamlit as stimport os, datetime, json, sys, pathlib, shutilimport pandas as pdimport streamlit as stimport cv2import face_recognitionimport numpy as npfrom PIL import Imageimport torchimport torch.nn.functional as Ffrom torch.nn import Linear, Conv2d, BatchNorm1d, BatchNorm2d, PReLU, ReLU, Sigmoid, AdaptiveAvgPool2d, Sequential, ModuleCOLOR_DARK  = (0, 0, 153)COLOR_WHITE = (255, 255, 255)def BGR_to_RGB(image_in_array):    return cv2.cvtColor(image_in_array, cv2.COLOR_BGR2RGB)def main():    ###################################################    st.sidebar.header("About")    st.sidebar.info("This webapp gives a demo of Visitor Monitoring ""Webapp using 'Face Recognition' and Streamlit")    ##################################################    ## Reading Camera Image    img_file_buffer = st.camera_input("Take a picture")    if img_file_buffer is not None:        bytes_data = img_file_buffer.getvalue()        # convert image from opened file to np.array        image_array         = cv2.imdecode(np.frombuffer(bytes_data,                                                            np.uint8),                                            cv2.IMREAD_COLOR)        image_array_copy    = cv2.imdecode(np.frombuffer(bytes_data, np.uint8), cv2.IMREAD_COLOR)        # st.image(cv2_img)        ## Saving Visitor History        ## Validating Image        # Detect faces in the loaded image        max_faces   = 0        rois        = []  # region of interests (arrays of face areas)        ## To get location of Face from Image        face_locations  = face_recognition.face_locations(image_array)        ## To encode Image to numeric format        encodesCurFrame = face_recognition.face_encodings(image_array,                                                            face_locations)        ## Generating Rectangle Red box over the Image        for idx, (top, right, bottom, left) in enumerate(face_locations):            # Save face's Region of Interest            rois.append(image_array[top:bottom, left:right].copy())            # Draw a box around the face and label it            cv2.rectangle(image_array, (left, top), (right, bottom), COLOR_DARK, 2)            cv2.rectangle(image_array, (left, bottom + 35), (right, bottom), COLOR_DARK, cv2.FILLED)            font = cv2.FONT_HERSHEY_DUPLEX            cv2.putText(image_array, f"#{idx}", (left + 5, bottom + 25), font, .55, COLOR_WHITE, 1)        ## Showing Image        st.image(BGR_to_RGB(image_array), width=720)        ## Number of Faces identified        max_faces = len(face_locations)        if max_faces > 0:            col1, col2 = st.columns(2)            # select selected faces in the picture            face_idxs = col1.multiselect("Select face#", range(max_faces),                                            default=range(max_faces))            ## Filtering for similarity beyond threshold            similarity_threshold = col2.slider('Select Threshold for Similarity',                                                    min_value=0.0, max_value=1.0,                                                    value=0.5)                                            ## check for similarity confidence greater than this threshold            flag_show = False#######################################################if __name__ == "__main__":    main()#######################################################

I'm not sure why my code crashes without any logs when I use the PyTorch module and the face_recognition module simultaneously. I haven't done any research beyond asking this question, but I've found that the code only runs if I import one of the modules at a time.

i wanted to create a streamlit application that able to take picture and detect the face encoding on it.


Viewing all articles
Browse latest Browse all 16743

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>