This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def predict(self, img_path: str): | |
"""Predicts how attractive is the person on the image""" | |
img = DeepFace.functions.load_image(img_path) | |
pil_to_predict = self.detect_face_with_padding(img, 0.2) | |
if pil_to_predict is None: | |
return (None,) * 3 | |
gender = self.predict_clip(pil_to_predict, ["man", "woman"]).argmax() | |
score = self.predict_clip(pil_to_predict, self.captions[gender])[0][0] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@torch.no_grad() | |
def predict_clip(self, image: Image.Image, text: List[str]): | |
text = clip.tokenize(text).to(self.device) | |
text_features = self.model.encode_text(text) | |
text_features /= text_features.norm(dim=1, keepdim=True) | |
image = self.preprocess(image).unsqueeze(0).to(self.device) | |
image_features = self.model.encode_image(image) | |
image_features /= image_features.norm(dim=1, keepdim=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PredictorCLIP(nn.Module): | |
def __init__(self, device="cpu"): | |
super().__init__() | |
self.device = device | |
# Loading CLIP | |
self.model, self.preprocess = clip.load("ViT-B/32", device=device) | |
# Loading BlazeFace detector from Mediapipe | |
self.detector = MediapipeWrapper.build_model() | |
self.captions = [["handsome", "ugly"], ["beautiful", "ugly"]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def detect_face_with_padding(self, img, padding=0.1): | |
"""Detects faces in an image. Returns first detected face. Returns None if no face detected.""" | |
try: | |
w, h, _ = img.shape | |
padding_coef_v = 1 + padding | |
padding_coef_h = 1 + padding | |
bbox = MediapipeWrapper.detect_face(self.detector, img)[0][1] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gpustat | |
import tqdm | |
import time | |
import seaborn as sns | |
import numpy as np | |
import pandas as pd | |
# Query for 6 seconds (step is 0.1 second) | |
gpu_stats = [] | |
for i in range(60): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Vast.ai script""" | |
import argparse | |
import subprocess | |
from pathlib import Path | |
import sysrsync | |
folders_to_sync = [ | |
("/root/data", "/root/data"), | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -ur %folder1% %folder2% | ydiff -s |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FILES=/data/datasets/files.txt | |
COUNTER=0 | |
LARGEFILES_CNT=0 | |
SMALLFILES_CNT=0 | |
start=`date +%s` | |
for f in `cat $FILES`; do | |
# INFO: IF ENDS AT: | |
# if [[ $COUNTER -gt 50 ]]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_local_and_global_vertex_coordinates(): | |
"""First you need to select a vertex in 'Edit Mode'""" | |
obj = bpy.context.selected_objects[0] | |
coords_local = obj.data.vertices[0].co | |
coords_global = obj.matrix_world @ coords_local | |
return coords_local, coords_global |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Convert cvPixelBuffer or cvPixelBufferRef to UIImage | |
let capturedUIImage = UIImage(ciImage: CIImage(cvPixelBuffer: capturedImage)) |