Spaces:
Paused
Paused
ResearcherXman commited on
Commit ·
43c2435
1
Parent(s): fc43999
update
Browse files23 unmodified lines2425262728293031323334353637383940414243444546474849505152535449 unmodified lines10410510610710810923 unmodified linesfrom transformers import DPTImageProcessor, DPTForDepthEstimationimport gradio as grdef get_depth_map(image):image = feature_extractor(images=image, return_tensors="pt").pixel_values.to("cuda")with torch.no_grad(), torch.autocast("cuda"):depth_map = depth_estimator(image).predicted_depthdepth_map = torch.nn.functional.interpolate(depth_map.unsqueeze(1),size=(1024, 1024),mode="bicubic",align_corners=False,)depth_min = torch.amin(depth_map, dim=[1, 2, 3], keepdim=True)depth_max = torch.amax(depth_map, dim=[1, 2, 3], keepdim=True)depth_map = (depth_map - depth_min) / (depth_max - depth_min)image = torch.cat([depth_map] * 3, dim=1)image = image.permute(0, 2, 3, 1).cpu().numpy()[0]image = Image.fromarray((image * 255.0).clip(0, 255).astype(np.uint8))return imagedef get_canny_image(image, t1=100, t2=200):image = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)edges = cv2.Canny(image, t1, t2)return Image.fromarray(edges, "L")# global variableMAX_SEED = np.iinfo(np.int32).maxdevice = "cuda" if torch.cuda.is_available() else "cpu"49 unmodified linescontrolnet_depth_model, torch_dtype=dtype).to(device)controlnet_map = {"pose": controlnet_pose,"canny": controlnet_canny,23 unmodified lines24252627282949 unmodified lines79808182838485868788899091929394959697989910010110210310410510610710810923 unmodified linesfrom transformers import DPTImageProcessor, DPTForDepthEstimationimport gradio as gr# global variableMAX_SEED = np.iinfo(np.int32).maxdevice = "cuda" if torch.cuda.is_available() else "cpu"49 unmodified linescontrolnet_depth_model, torch_dtype=dtype).to(device)def get_depth_map(image):image = feature_extractor(images=image, return_tensors="pt").pixel_values.to("cuda")with torch.no_grad(), torch.autocast("cuda"):depth_map = depth_estimator(image).predicted_depthdepth_map = torch.nn.functional.interpolate(depth_map.unsqueeze(1),size=(1024, 1024),mode="bicubic",align_corners=False,)depth_min = torch.amin(depth_map, dim=[1, 2, 3], keepdim=True)depth_max = torch.amax(depth_map, dim=[1, 2, 3], keepdim=True)depth_map = (depth_map - depth_min) / (depth_max - depth_min)image = torch.cat([depth_map] * 3, dim=1)image = image.permute(0, 2, 3, 1).cpu().numpy()[0]image = Image.fromarray((image * 255.0).clip(0, 255).astype(np.uint8))return imagedef get_canny_image(image, t1=100, t2=200):image = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)edges = cv2.Canny(image, t1, t2)return Image.fromarray(edges, "L")controlnet_map = {"pose": controlnet_pose,"canny": controlnet_canny,
app.py+25-25