|
|
|
|
|
|
|
|
|
|
|
|
|
from VidProM.isc.io import read_descriptors |
|
|
|
|
|
|
|
|
|
|
|
vid_name, vid_feature = read_descriptors(['./VidProM/vidprom_embed.hdf5']) |
|
|
|
|
|
|
|
|
|
|
|
vid_feature.shape |
|
|
|
|
|
|
|
|
|
|
|
import re |
|
|
|
def remove_numbers_and_words(s): |
|
|
|
s = re.sub(r'\d+', '', s) |
|
|
|
s = re.sub(r'(image|message|attachment|quot|make)', '', s, flags=re.IGNORECASE) |
|
return s |
|
|
|
|
|
|
|
|
|
|
|
import pandas as pd |
|
df = pd.read_csv('./prompts4video_unique.csv') |
|
imdb_reviews = list(df['prompt']) |
|
imdb_reviews_clean = [i.split('-')[0] for i in imdb_reviews] |
|
vidprom_prompts = [remove_numbers_and_words(i) for i in imdb_reviews_clean] |
|
|
|
|
|
|
|
|
|
|
|
len(vidprom_prompts) |
|
|
|
|
|
|
|
|
|
|
|
diffdb_name, diffdb_feature = read_descriptors(['./DiffusionDB/diffusiondb_embed.hdf5']) |
|
|
|
|
|
|
|
|
|
|
|
diffdb_feature.shape |
|
|
|
|
|
|
|
|
|
|
|
import pandas as pd |
|
path_to_prompt_parquet = "DiffusionDB/metadata-large.parquet" |
|
prompts = pd.read_parquet( |
|
path_to_prompt_parquet, |
|
columns=['prompt'] |
|
) |
|
diffdb_prompts = sorted(list(set(prompts['prompt']))) |
|
print("Length of prompts: ", len(diffdb_prompts)) |
|
|
|
|
|
|
|
|
|
|
|
diffdb_prompts_1 = list(set(prompts['prompt'])) |
|
|
|
|
|
|
|
|
|
|
|
with open("diffusiondb_prompts.txt", 'w', encoding='utf-8') as file: |
|
for fruit in diffdb_prompts_1: |
|
file.write(fruit + '\n') |
|
|
|
|
|
|
|
|
|
|
|
len(diffdb_prompts_1) |
|
|
|
|
|
|
|
|
|
|
|
hf.upload_file(path_or_fileobj="./wizmap_vidprom_diffusiondb_final/data_vidprom_diffusiondb.ndjson", \ |
|
path_in_repo="data_vidprom_diffusiondb.ndjson", repo_id="WenhaoWang/VidProM", \ |
|
repo_type="dataset") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import umap |
|
import numpy as np |
|
embedding_0 = umap.UMAP(n_neighbors=60, |
|
min_dist=0.1, |
|
metric='correlation').fit_transform(np.concatenate([vid_feature,diffdb_feature])) |
|
|
|
|
|
|
|
|
|
|
|
np.save('umap_diffusiondb_vidprom.npy', embedding_0) |
|
|
|
|
|
|
|
|
|
|
|
import numpy as np |
|
embedding_0 = np.load('umap_diffusiondb_vidprom.npy') |
|
|
|
|
|
|
|
|
|
|
|
texts = vidprom_prompts + diffdb_prompts |
|
xs = embedding_0[:, 0].astype(float).tolist() |
|
ys = embedding_0[:, 1].astype(float).tolist() |
|
|
|
|
|
|
|
|
|
|
|
from glob import glob |
|
from os.path import exists, join, basename |
|
from tqdm import tqdm |
|
from json import load, dump |
|
from matplotlib import pyplot as plt |
|
from collections import Counter |
|
|
|
from sklearn.feature_extraction.text import CountVectorizer, TfidfTransformer |
|
from quadtreed3 import Quadtree, Node |
|
from scipy.sparse import csr_matrix |
|
from sklearn.neighbors import KernelDensity |
|
from scipy.stats import norm |
|
from typing import Tuple |
|
from io import BytesIO |
|
from umap import UMAP |
|
|
|
import pandas as pd |
|
import numpy as np |
|
import ndjson |
|
import requests |
|
import urllib |
|
import wizmap |
|
|
|
SEED = 20230501 |
|
|
|
plt.rcParams['figure.dpi'] = 300 |
|
|
|
|
|
|
|
|
|
|
|
labels = [0]*len(vidprom_prompts) + [1] *len(diffdb_prompts) |
|
|
|
|
|
|
|
|
|
|
|
len(labels) |
|
|
|
|
|
|
|
|
|
|
|
group_names = ["VidProM", "DiffusionDB"] |
|
|
|
|
|
|
|
|
|
|
|
grid_dict = wizmap.generate_grid_dict(embedding_0[:, 0].astype(float).tolist(), \ |
|
embedding_0[:, 1].astype(float).tolist(), \ |
|
texts, \ |
|
embedding_name = 'VidProM_DiffusionDB', \ |
|
labels = labels, \ |
|
group_names = group_names) |
|
|
|
|
|
|
|
|
|
|
|
print(grid_dict.keys()) |
|
|
|
|
|
|
|
|
|
|
|
data_list = wizmap.generate_data_list(xs, ys, texts, labels = labels) |
|
|
|
|
|
|
|
|
|
|
|
get_ipython().system('mkdir wizmap_vidprom_diffusiondb_final') |
|
|
|
|
|
|
|
|
|
|
|
wizmap.save_json_files(data_list, grid_dict, output_dir='./wizmap_vidprom_diffusiondb_final') |
|
|
|
|
|
|
|
|
|
|
|
get_ipython().system('mv ./wizmap_vidprom_diffusiondb_final/data.ndjson ./wizmap_vidprom_diffusiondb_final/data_vidprom_diffusiondb.ndjson') |
|
|
|
|
|
|
|
|
|
|
|
get_ipython().system('mv ./wizmap_vidprom_diffusiondb_final/grid.json ./wizmap_vidprom_diffusiondb_final/grid_vidprom_diffusiondb.json') |
|
|
|
|
|
|
|
|
|
|
|
import os |
|
|
|
|
|
os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1" |
|
|
|
from huggingface_hub import HfApi, logging |
|
|
|
logging.set_verbosity_debug() |
|
hf = HfApi( |
|
endpoint="https://huggingface.co", |
|
token="xxxx", |
|
) |
|
|
|
|
|
|
|
|
|
|
|
hf.upload_file(path_or_fileobj="./wizmap_vidprom_diffusiondb_final/grid_vidprom_diffusiondb.json", \ |
|
path_in_repo="grid_vidprom_diffusiondb.json", repo_id="WenhaoWang/VidProM", \ |
|
repo_type="dataset") |
|
|
|
|
|
|
|
|
|
|
|
hf.upload_file(path_or_fileobj="./wizmap_vidprom_diffusiondb_final/grid_vidprom_diffusiondb.json", \ |
|
path_in_repo="grid_vidprom_diffusiondb.json", repo_id="WenhaoWang/VidProM", \ |
|
repo_type="dataset") |
|
|
|
|
|
|
|
|
|
|
|
hf.upload_file(path_or_fileobj="./wizmap_vidprom_diffusiondb_final/data_vidprom_diffusiondb.ndjson", \ |
|
path_in_repo="data_vidprom_diffusiondb.ndjson", repo_id="WenhaoWang/VidProM", \ |
|
repo_type="dataset") |
|
|
|
|
|
|