4.5 KiB
4.5 KiB
In [ ]:
import base64
import json
import requests
import io
import numpy as np
import PIL.Image
import cv2
from pprint import pprint
def process_image(path_img):
with open(path_img, "rb") as image_file:
encoded_string = base64.b64encode(image_file.read()).decode('utf-8')
response = requests.post(
'http://localhost:5000/process',
headers={'Content-Type': 'application/json'},
data=json.dumps({'image': encoded_string})
)
response_dict = response.json()
pprint(response_dict)
# Decode
image_bytes = base64.b64decode(response_dict.get("image_b64"))
img_array = np.frombuffer(io.BytesIO(image_bytes).getvalue(), dtype=np.uint8)
img_bgr = cv2.imdecode(img_array, cv2.IMREAD_COLOR)
img_rgb = img_bgr[:, :, ::-1]
return img_rgbIn [ ]:
path_img = "imgs/img_1p.jpg"
PIL.Image.fromarray( process_image(path_img) )In [ ]:
path_img = "imgs/img_nude.jpg"
PIL.Image.fromarray( process_image(path_img) )In [ ]:
In [ ]:
In [ ]:
In [ ]:
'''
# !git clone https://github.com/wildchlamydia/mivolo
# !pip install ultralytics yt_dlp pandas scipy timm==0.8.13.dev0
# !pip install ./mivolo
!python mivolo/demo.py \
--input "face_data/sample_image.jpg" \
--output "output" \
--detector-weights "mivolo/pretrained/yolov8x_person_face.pt" \
--checkpoint "mivolo/pretrained/model_imdb_cross_person_4.22_99.46.pth.tar" \
--device "cpu" \
--draw
'''
'''
# !git clone https://github.com/Kartik-3004/facexformer.git
# !pip install huggingface_hub torch torchvision torchaudio opencv-python facenet_pytorch
from huggingface_hub import hf_hub_download
hf_hub_download(repo_id="kartiknarayan/facexformer", filename="ckpts/model.pt", local_dir="./facexformer")
!python facexformer/inference.py \
--model_path facexformer/ckpts/model.pt \
--image_path face_data/sample_image.jpg \
--results_path face_data \
--task parsing
x
!python facexformer/inference.py \
--model_path facexformer/ckpts/model.pt \
--image_path face_data/face.png \
--results_path face_data \
--task landmarks
!python facexformer/inference.py \
--model_path facexformer/ckpts/model.pt \
--image_path face_data/face.png \
--results_path face_data \
--task headpose
!python facexformer/inference.py \
--model_path facexformer/ckpts/model.pt \
--image_path face_data/face.png \
--results_path face_data \
--task attributes
!python facexformer/inference.py \
--model_path facexformer/ckpts/model.pt \
--image_path face_data/face.png \
--results_path face_data \
--task age_gender_race
'''