Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running example.py without docker #52

Open
gd1925 opened this issue Aug 2, 2023 · 6 comments
Open

Running example.py without docker #52

gd1925 opened this issue Aug 2, 2023 · 6 comments

Comments

@gd1925
Copy link

gd1925 commented Aug 2, 2023

image
Hi,
Thank you for the awesome work.
I wanted to try the code without using docker. But I am running into the above error. Could you provide some guidance? I also wanted to run a webcam demo, could you maybe provide with the some code snippet for it too? I checked the analyzer function can only take frames. Thank you.

@tomas-gajarsky
Copy link
Owner

Thank you for the feedback.

To get a detailed error message, please set the environment variable HYDRA_FULL_ERROR=1 as suggested in the logs, then share the full error here.

For an example of using facetorch outside Docker, refer to the Colab notebook. Feel free to reach out if you need further assistance!

@gd1925
Copy link
Author

gd1925 commented Aug 10, 2023

Hi @tomas-gajarsky, Thank you so much for your reply. So I did export HYDRA_FULL_ERROR=1 and also, since I dont want to use docker, I tried to change the paths - /opt/facetorch to my path to models folder in the gpu.config.yml file. Now I am getting this error -
image
image
image

Could you provide some pointers on how to make it run? Thank you again!!

@tomas-gajarsky
Copy link
Owner

I can see that facetorch is still trying to create directories in the /opt/ directory, which means that you haven't changed all the paths in the config file or that the wrong config file is being used.

The example.py script is using the main config.yaml file located in the conf/ folder by default. It composes the full configuration from files located in conf/analyzer.

@gd1925
Copy link
Author

gd1925 commented Aug 14, 2023

Thanks you for your reply. There were some files which I had indeed missed out and changing those resolved the errors. I was also able to run the demo collab file as a python script following the same.
I am currently trying to modify it to run for video and webcam. But I am finding it hard to process the frames in the correct way. My code is as follows:

import cv2
from facetorch import FaceAnalyzer
from omegaconf import OmegaConf
from torch.nn.functional import cosine_similarity
from typing import Dict
import operator
import torchvision

path_config="cpu.config.yaml"
cfg = OmegaConf.load(path_config)

analyzer = FaceAnalyzer(cfg.analyzer)

def process_frame(frame):
    pil_image = torchvision.transforms.functional.to_pil_image(frame)
    
    response = analyzer.run(
        path_image=pil_image,
        batch_size=cfg.batch_size,
        fix_img_size=cfg.fix_img_size,
        return_img_data=cfg.return_img_data,
        include_tensors=cfg.include_tensors
    )
    
    # Convert tensor back to OpenCV frame
    processed_frame = cv2.cvtColor(np.array(response.img), cv2.COLOR_RGB2BGR)
    
    return processed_frame

video_capture = cv2.VideoCapture(0) 

while True:
    ret, frame = video_capture.read()
    if not ret:
        print("Failed to grab the frame")
        break
    cv2.imshow('Raw frame', frame)
    processed_frame = process_frame(frame)

    cv2.imshow('Live Webcam - Processed', processed_frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

video_capture.release()
cv2.destroyAllWindows()

The output frame seems to be corrupted (black background with some coloured vertical lines). The raw frame seems to be okay, but processed frame onwards, I dont quite understand. Could you provide me with some reference or pointers for this as well?

@tomas-gajarsky
Copy link
Owner

You are passing a PIL image to the run function, but it can only take a string representing the path to the image as input.

For your plan to work, it would require implementing a new version of ImageReader that takes PIL images as input and adjusting the run function or creating a new analyzer function. That could be an awesome contribution!

You could try saving the frame image from the webcam first and then passing it to the analyzer, but I think that it would be too slow. In general, I am not sure if a webcam demo with facetorch running on the CPU is possible. Perhaps only with one predictor, small image size, and low video frame rate.

@gd1925
Copy link
Author

gd1925 commented Aug 17, 2023

Hi @tomas-gajarsky , okay I get it now!!
Thanks for your immense help and the tips!! :D
About the newer version of ImageReader , I will give it a shot and see if I can do it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants