text stringlengths 0 93.6k |
|---|
# corresponds to doing no classifier free guidance. |
do_classifier_free_guidance = guidance_scale > 1.0 |
# get unconditional embeddings for classifier free guidance |
if do_classifier_free_guidance: |
max_length = text_input.input_ids.shape[-1] |
uncond_input = self.tokenizer( |
[""] * batch_size, padding="max_length", max_length=max_length, return_tensors="pt" |
) |
uncond_embeddings = self.text_encoder(uncond_input.input_ids.to(self.device))[0] |
# For classifier free guidance, we need to do two forward passes. |
# Here we concatenate the unconditional and text embeddings into a single batch |
# to avoid doing two forward passes |
text_embeddings = torch.cat([uncond_embeddings, text_embeddings]) |
# prepare extra kwargs for the scheduler step, since not all schedulers have the same signature |
# eta (η) is only used with the DDIMScheduler, it will be ignored for other schedulers. |
# eta corresponds to η in DDIM paper: https://arxiv.org/abs/2010.02502 |
# and should be between [0, 1] |
accepts_eta = "eta" in set(inspect.signature(self.scheduler.step).parameters.keys()) |
extra_step_kwargs = {} |
if accepts_eta: |
extra_step_kwargs["eta"] = eta |
latents = init_latents |
t_start = max(num_inference_steps - init_timestep + offset, 0) |
for i, t in tqdm(enumerate(self.scheduler.timesteps[t_start:])): |
# expand the latents if we are doing classifier free guidance |
latent_model_input = torch.cat([latents] * 2) if do_classifier_free_guidance else latents |
# predict the noise residual |
noise_pred = self.unet(latent_model_input, t, encoder_hidden_states=text_embeddings)["sample"] |
# perform guidance |
if do_classifier_free_guidance: |
noise_pred_uncond, noise_pred_text = noise_pred.chunk(2) |
noise_pred = noise_pred_uncond + guidance_scale * (noise_pred_text - noise_pred_uncond) |
# compute the previous noisy sample x_t -> x_t-1 |
latents = self.scheduler.step(noise_pred, t, latents, **extra_step_kwargs)["prev_sample"] |
# scale and decode the image latents with vae |
latents = 1 / 0.18215 * latents |
image = self.vae.decode(latents) |
image = (image / 2 + 0.5).clamp(0, 1) |
image = image.cpu().permute(0, 2, 3, 1).numpy() |
# run safety checker |
safety_cheker_input = self.feature_extractor(self.numpy_to_pil(image), return_tensors="pt").to(self.device) |
#image_, has_nsfw_concept = self.safety_checker(images=image, clip_input=safety_cheker_input.pixel_values) |
has_nsfw_concept = [] |
for hni in range(0, len(image)): |
has_nsfw_concept.append(0) |
if output_type == "pil": |
image = self.numpy_to_pil(image) |
return {"sample": image, "nsfw_content_detected": has_nsfw_concept} |
# <FILESEP> |
#!/usr/local/bin/python |
# -*- coding:utf-8 -*- |
# @Time : 2019/4/10 10:10 PM |
# @Author : Jerry |
# @Desc : |
# @File : SensitivesHunter.py |
import json |
import os |
import sys |
import subprocess |
from lib.config import log |
from lib.common.basic import getCurrentPath, makeDir, getDomain |
from Downloader import DownLoader |
from SensitiveFileParser import SensitiveFileParser |
import config |
class SensitivesHunter(): |
def __init__(self, url, project_name): |
self.start_url = url |
self.project_name = project_name |
self.crawled_file_links_dict = {} |
self.result_dict = {} |
self.skip_flag = False # 跳过爬取的标志 |
def startHunt(self): |
self.prepare() |
self.tryToSkipCrawled() |
if not self.skip_flag: |
self.crawlLinks() # 爬取链接 |
self.parseFileLinks() # 解析爬取到的文件url |
for file_type, url_file_list in self.crawled_file_links_dict.items(): |
downloaded_file_path_dict = self.downloadFile(url_file_list, file_type) |
self.detectSensitiveFile(downloaded_file_path_dict, file_type) |
self.saveResultFile() |
def tryToSkipCrawled(self): |
''' |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.