Пример #1
0
def main():
    args = parser.parse_args()
    casc_type = os.path.abspath('./data/lbpcascade_frontalface.xml')
    # casc_type = os.path.abspath('./data/haarcascade_frontalface_default.xml')
    face_cascade = cv2.CascadeClassifier(casc_type)

    # Training data
    # face_recognizer = cv2.face.createLBPHFaceRecognizer()
    # face_recognizer = cv2.face.LBPHFaceRecognizer_create()

    # or use EigenFaceRecognizer by replacing above line with
    # face_recognizer = cv2.face.createEigenFaceRecognizer()
    # face_recognizer = cv2.face.EigenFaceRecognizer_create()

    # or use FisherFaceRecognizer by replacing above line with
    # face_recog = cv2.face.createFisherFaceRecognizer()
    face_recog = cv2.face.FisherFaceRecognizer_create()
    folder_path = os.path.abspath('./training_sets')
    if args.add != 'none':
        get_photos.main(args.add, args.num)
    if args.train:
        print("Preparing data...")
        faces, labels, names = train_model.prepare_training_data(
            face_cascade, folder_path)
        print("Data prepared")

        # print total faces and labels
        print("Total faces: ", len(faces))
        print("Total labels: ", len(labels))
        print(names)

        face_recog = train_model.recognizer(faces, labels)
    else:
        face_recog.read(args.model)
        names = getNamesMap(folder_path)

    vid = cv2.VideoCapture(0)
    in_row_count = 0
    while True:
        ret, frame = vid.read()
        image, conf, name = train_model.predict(face_cascade, frame,
                                                face_recog, names)

        if image is not None:
            cv2.imshow("Faces found", image)

        if conf < 350:
            in_row_count += 1
        else:
            in_row_count = 0

        if in_row_count > 10:
            print("Unlocked user %s!" % name)
            in_row_count = 0

        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

    vid.release()
    cv2.destroyAllWindows()
Пример #2
0
def main():
    detector = dlib.get_frontal_face_detector()

    cam = cv2.VideoCapture(0)
    success, frame = cam.read()

    while success and cv2.waitKey(1) == -1:
        success, frame = cam.read()
        gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
        faces = detector(gray, 1)

        for i, d in enumerate(faces):
            x = d.top() if d.top() > 0 else 0
            w = d.bottom() if d.bottom() > 0 else 0
            y = d.left() if d.left() > 0 else 0
            h = d.right() if d.right() > 0 else 0

            det = frame[x:x + w, y:y + h]
            det = cv2.resize(det, (img_size, img_size),
                             interpolation=cv2.INTER_LINEAR)

            label, prob = predict(model, det)
            if prob > 0.9:
                show_name = name_list[label]
            else:
                show_name = 'Unknown'
            cv2.putText(frame, show_name, (y, w - 20),
                        cv2.FONT_HERSHEY_SIMPLEX, 1, 255, 2)
            frame = cv2.rectangle(frame, (y, x), (h, w), (255, 0, 0), 2)
        cv2.imshow("Camera", frame)

    cam.release()
    cv2.destroyAllWindows()
Пример #3
0
def main():
    cam = cv2.VideoCapture(0)
    success, frame = cam.read()

    while success and cv2.waitKey(1) == -1:
        success, frame = cam.read()

        det = cv2.resize(frame, (img_size, img_size),
                         interpolation=cv2.INTER_LINEAR)
        # det = image.array_to_img(det)

        label, prob = predict(model, det)
        if prob > 0.9:
            show_name = name_list[label]
        else:
            show_name = 'Unknown'
        cv2.putText(frame, show_name, (20, img_size - 20),
                    cv2.FONT_HERSHEY_SIMPLEX, 1, 255, 2)
        # frame = cv2.rectangle(frame, (y, x), (h, w), (255, 0, 0), 2)
        cv2.imshow("Camera", frame)

    cam.release()
    cv2.destroyAllWindows()
Пример #4
0
import train_model
import DataPreprocessing

hidden_layer_dims = [7, 8]
layer_types = ['relu', 'relu', 'sigmoid']
learning_rate = 0.001
num_iterations = 1000
# num_batches = 6
lambd = 0
prob = 1
threshold = 0.5

X_train_scaled, X_test_scaled, Y_train, Y_test = DataPreprocessing.opendata(
    "wine.csv", "DNN")
X_train_tr = X_train_scaled.T
Y_train_tr = Y_train.T
Y_test = Y_test.T
X_test_scaled = X_test_scaled.T

params = train_model.model(X_train_tr, Y_train_tr, hidden_layer_dims,
                           layer_types, learning_rate, num_iterations, prob)

yptest, accuracytest = train_model.predict(X_test_scaled, Y_test, params,
                                           hidden_layer_dims, layer_types, 0.5)
print('The accuracy of training set is: %d' % accuracytest)

yptrain, accuracytrain = train_model.predict(X_train_tr, Y_train_tr, params,
                                             hidden_layer_dims, layer_types,
                                             0.5)
print('The accuracy of testing set is: %d' % accuracytrain)
Пример #5
0
st.warning(
    "Tell us which nootropics you have tried. For each substance, please rate your subjective experience on a scale of 0 to 10. 0 means a substance was totally useless, or had so many side effects you couldn't continue taking it. 1 - 4 means for subtle effects, maybe placebo but still useful. 5 - 9 means strong effects, definitely not placebo. 10 means life-changing."
)

slider_dic = {}
checkbox_dic = {}
for nootropic in nootropics_list:
    checkbox_dic[nootropic] = st.checkbox("I've tried {}".format(nootropic))
    if checkbox_dic[nootropic]:
        slider_dic[nootropic] = st.slider("{} rating".format(nootropic),
                                          min_value=0,
                                          max_value=10)
    # form = st.form(key=nootropic)
    # form.text_input(label="{} rating".format(nootropic))
    # form_dic[nootropic] = form
    # submit_button = st.form_submit_button(label='Submit')

if st.button("I'm done rating and would like to see predictions"):
    new_result_df = predict(slider_dic)
    st.write("Our model predicted this ratings for you:")
    st.write(new_result_df)

if st.button("How accurate is your model ?"):
    if len(slider_dic) < 2:
        st.error("Please rate at least two nootropics")
    else:
        accuracy_df = evaluate(slider_dic)
        st.write(
            "For each nootropic, we hid your rating to our model, and had the model try to guess it."
        )
        st.write(accuracy_df)
Пример #6
0
import insta_api
import train_model

# Train the RF classifier
print()
print("Training results: ")
train_model.train()
print()

# Driver
while (True):
    username = input(
        "Enter username of user you want to verify whether they are a bot or not: "
    )
    if (username):
        features = insta_api.features(username)
        if features:
            print(train_model.predict(features))