Exemplo n.º 1
0
    preds = [preds[1], preds[2]]
    return preds


preprocess_input = preprocess_input

# Init drawer and xai_tool
drawer = Drawer()
xai_tool = XAITool(model, input_size, decode, preprocess_input)
cap = cv2.VideoCapture(0)
while (True):
    ret_run, frame = cap.read()
    xai_dict = xai_tool.vidCapRun(frame, -1)
    if ('predictions' in xai_dict):
        drawer.singleThread(frame, xai_dict['heatmap'],
                            xai_dict['activations'], xai_tool.layers[-1], -1,
                            xai_dict['predictions'])
    else:
        drawer.singleThread(frame, xai_dict['heatmap'],
                            xai_dict['activations'], xai_tool.layers[-1], -1)
# TEMP
# cap = cv2.VideoCapture(0)
# ret_run, frame = cap.read()
# cv2.imshow('hello', frame)
# cv2.waitKey(100)
# # testing custom models
# from keras.models import load_model
# import keras
# cus_model = load_model('models/TIL_Pose_detector.h5')
# input_size = (224, 224)
Exemplo n.º 2
0
decode = createDecoder(target_labels)

# Init classes
drawer = Drawer()
cap = cv2.VideoCapture(0)
xai_tool = XVisTool(model,
                    input_size,
                    decoder_func=decode,
                    preprocess_img_func=preprocess_input)

# Showing the default
ori_img = xai_tool.setStillImg(img_path)
xai_dict = xai_tool.stillImgRun(-1)
layers = xai_tool.layers

drawer.singleThread(ori_img, xai_dict['heatmap'], xai_dict['activations'],
                    [layers[-1], -1], xai_dict['predictions'])
cv2.imshow('XVis Single', drawer.mask)
cv2.waitKey(100)
while (True):
    print('These are the layers you can select: ')
    for i, layer in enumerate(layers):
        print('Layer ({}): {}'.format(i + 1, layer))
    selected_layer = getSelectedLayer(layers)
    xai_dict = xai_tool.stillImgRun(selected_layer)
    drawer.singleThread(ori_img, xai_dict['heatmap'], xai_dict['activations'],
                        [layers[selected_layer], selected_layer],
                        xai_dict['predictions'])
    cv2.imshow('XVis Single', drawer.mask)
    cv2.waitKey(100)