AIGC

+++ title = ‘AIGC’ tags = [“AI”] draft = false +++ Image Stable Diffusion text_encoder: Stable Diffusion uses CLIP, but other diffusion models may use other encoders such as BERT tokenizer: must match the one used by the text_encoder model scheduler: the scheduling algorithm used to progressively add noise to the image during training unet: the model used to generate the latent representation of the input vae: autoencoder module that we’ll use to decode latent representations into real images Tutorial Generative Modeling by Estimating Gradients of the Data Distribution The Annotated Diffusion Model Stable Diffusion with Diffusers Install conda create --name=ai python=3.10.9 sudo apt install nvidia-cuda-toolkit pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118 pip install transformers noglob pip3 install diffusers["torch"] pip install -U xformers Colab How to Use Stable Diffusion to Generate Images Stable diffusion web-ui References ...

January 1, 2000

Autonomous Vehicles

Definitions 开环 闭环 在环 回灌 PCAP:网络数据包 PCD文件:点云帧 CAN/CANFD: 总线数据包和车载以太网数据包 Tutorials 知乎 - 自动驾驶学习资料合集 Github - Road-To-Autonomous-Driving Birds-eye-view-Perception To Read Data Lake https://www.youtube.com/watch?v=Sguvhvwn8m4&list=PL-gIUf9e9CCtGr_zYdWieJhiqBG_5qSPa https://www.youtube.com/watch?v=MaQQmjtFUK8 https://aws.amazon.com/blogs/architecture/field-notes-building-an-autonomous-driving-and-adas-data-lake-on-aws/ Iceberg https://iceberg.apache.org/spark-quickstart/ AVOps https://learn.microsoft.com/en-us/azure/architecture/example-scenario/automotive/autonomous-vehicle-operations-dataops https://aws.amazon.com/cn/blogs/china/autonomous-driving-data-lake-scene-detection/ https://juicefs.com/zh-cn/blog/user-stories/li-autos-practice-of-migrating-data-from-hdfs-to-juicefs https://cloud.tencent.com/developer/article/2193529 https://www.cnblogs.com/yunqishequ/p/16876242.html https://chejiahao.autohome.com.cn/info/14983089 https://www.slidestalk.com/AWS.User_Group/59655?video https://developer.aliyun.com/article/1103513 https://learn.microsoft.com/zh-cn/azure/architecture/solution-ideas/articles/avops-architecture https://github.com/aws-samples/aws-autonomous-driving-data-lake-ros-bag-visualization-using-rviz https://www.databricks.com/dataaisummit/session/building-data-lakehouse-manage-pbs-autonomous-vehicle-data

January 1, 2000

ChatGPT

Ideas 3 levels Use chatgpt to do job make tools to facilitate the workflow of using chatgpt improve model to do job LLM Learning things by induction, Human can learn by deduction Learning Papers Recent Advances in Natural Language Processing via Large Pre-Trained Language Models- A Survey Articles 拆解追溯 GPT-3.5 各项能力的起源 Generative AI exists because of the transformer Prompt Engineering Prompting Principles Principle 1: Write clear and specific instructions Use delimiters to clearly indicate distinct parts of the input Ask for a structured output Ask the model to check whether conditions are satisfied “Few-shot” prompting Principle 2: Give the model time to “think” Specify the steps required to complete a task Instruct the model to work out its own solution before rushing to a conclusion Iterative Prompt Development ...

January 1, 2000

Computer Vision

Face Detection retina face Github - retinaface: deep learning based cutting-edge facial detector deepface Github - deepface: a lightweight face recognition and facial attribute analysis (age, gender, emotion and race) framework Install: pip install deepface Usage: from deepface import DeepFace # Detection: 从照片中检测人脸 face_objs = DeepFace.extract_faces( img_path = "img.jpg", detector_backend = 'retinaface', # retina face 检测效果较好 align = False, enforce_detection = False, ) # Verification: 判断两张图片是否同一个人 result = DeepFace.verify(img1_path = "img1.jpg", img2_path = "img2.jpg") # 默认会先做 detection,如果是已经提取了人脸的照片可以用 result = DeepFace.verify(img1_path = "img1.jpg", img2_path = "img2.jpg", detector_backend='skip') # 指定相似度阈值 result = DeepFace.verify(img1_path = "img1.jpg", img2_path = "img2.jpg", threshold=0.5) # Embedding: 提取人脸 embedding,可以用于后续的对比计算 embedding_objs = DeepFace.represent(img_path = "img.jpg") # Recognition: 人脸识别,从人脸库中找出最符合的人 dfs = DeepFace.find( img_path = "img1.jpg", db_path = "./workspace/my_db", model_name = "VGG-Face", # 默认模型是 VGG-Face ) # Analysis:提取脸部特征(年龄、性别、情绪等) objs = DeepFace.analyze( img_path = "img4.jpg", actions = ['age', 'gender', 'race', 'emotion'], )

January 1, 2000

Graph

Libraries DGL (Deep Graph Library) References Overview of DGL Pytorch Geometric Documentation Networkx # import import networkx as nx # load adjacency matrix G = nx.from_numpy_matrix(A) # get adjacency matrix A = nx.adjacency_matrix(G) A = nx.adjacency_matrix(G).todense() # drawing fig = plt.figure(figsize=(10,8)) ax = plt.subplot(111) pos = nx.spring_layout(G) #pos = nx.kamada_kawai_layout(G) nx.draw(G, ax=ax, pos=pos, node_size=10, node_color=colors, alpha=0.5, with_labels=True) # or nx.draw_networkx_nodes(G, ax=ax, pos=pos, node_size=100, node_color=colors, alpha=0.5) nx.draw_networkx_edges(G, ax=ax, pos=pos, alpha=0.1) # Laplacian Matrix lap = nx.linalg.laplacianmatrix.laplacian_matrix(G) lap = nx.linalg.laplacianmatrix.normalized_laplacian_matrix(G) # N=D^(-1/2)LD^(-1/2) # connected components nx.algorithms.components.number_connected_components(G) # relabel G = nx.relabel_nodes(G, lambda x: int(x[1:])) # get weights for n, nbrs in G.adj.items(): for nbr, eattr in nbrs.items(): wt = eattr['weight'] print('(%d, %d, %.3f)' % (n, nbr, wt)) for (u, v, wt) in G.edges.data('weight'): print('(%d, %d, %.3f)' % (u, v, wt)) # shorest path nx.shorest_paht(G, source, target) nx.shorest_paht_length(G, source, target) Projects deepwalk node2vec GraphEmbedding GraphSAGE graphsage-simple karateclub SINE Overlapping Community Detection with Graph Neural Networks

January 1, 2000

NLP

Terms NLU (Natural Language Understanding) / NLI (Natural Language Inferencing) NLG (Natural Language Generation) Tokenization (分词) Chinese Word Segmentation (中文分词) BPE/wordpiece/unigram Stemming (词干提取) Lemmatization (词形还原) Parts of speech tagging (词性标注) Named-entity Recognition (NER,命名实体识别) Chunking (分块) Language Model: A language model is a function that takes in a sequence of words and returns a probility distribution over all the possible next words in that sequence. autoregressive/causal language model masked language model (BERT) ...

January 1, 2000

Numpy-Pandas-SciPy

Numpy-Pandas-SciPy Numpy Basic Import import numpy as np Get shape x.shape Meshgrid x = np.arange(-5, 5, 0.1) y = np.arange(-5, 5, 0.1) xx, yy = np.meshgrid(x, y) z = np.sin(xx**2 + yy**2) / (xx**2 + yy**2) h = plt.contourf(x,y,z) Sort np.argmax(x) np.argsort(x) Matrix # change axes xx.transpose(1,0,2) Random Generate random samples # generate random integers over [low, high) with size d0*d1 from a uniform dist x = np.random.randint(low, high, (d0, d1)) # generate d0*d1*d2 samples from a uniform distribution over [0, 1) x = np.random.rand(d0, d1, d2) # generate d0*d1*d2 samples from a normal distribution over [0, 1) x = np.random.randn(d0, d1, d2) # generate n samples from a uniform distribution over [0, 1) x = np.random.random(n) x = np.random.sample(n) x = np.random.random_sample(n) x = np.random.randf(n) Make random choice ...

January 1, 2000

Prompts

Summurizing 结构 请为文章提供一个结构化的概要 理解 请介绍一下该技术的背景与发展历史。 请介绍一下主要特性与关键技术。 请列举上述介绍中涉及到的技术概念,请详细阐述涉及的每个概念,并举例说明。 (请重点解释上述概念间的差异与对比。) 使用 请介绍如何安装相关依赖或工具。 请介绍具体使用方式,并给出相应例子。 (简单介绍一下实际应用案例。) (使用中遇到哪些常见问题,如何解决。) 拓展 有没有类似工具,请对比其优劣 格式 请检查文章的格式,要求语句流畅,无错别字,格式美观,中英文间有空格,变量或命令用反括号。请直接返回校正后的文章。 Code Reading README 主要内容 依赖包,以及它们的功能 项目结构 文档、wiki Learning Summarising Summarise the above text into the most important points. Display the points as bullet points with short descriptions. Mind Map Create a mind map on the topic above. List out the central idea, main branches, and sub-branches. Active Recall I’ve recently immersed myself in studying [specific topic]. To ensure I’ve truly grasped the essence and intricacies, could you challenge my understanding by posing some deep, thought-provoking questions? This will not only test my recall of the main concepts and principles but also solidify my grasp on the finer details. ...

January 1, 2000

PyTorch

PyTorch PyTorch - QuickStart Basic # version torch.__version__ # PyTorch version torch.version.cuda # Corresponding CUDA version torch.backends.cudnn.version() # Corresponding cuDNN version torch.cuda.get_device_name(0) # GPU type # seed torch.manual_seed(0) torch.cuda.manual_seed_all(0) # GPU torch.cuda.is_available() os.environ['CUDA_VISIBLE_DEVICES'] = '0,1' torch.cuda.empty_cache() # clear GPU cache device = ( "cuda" if torch.cuda.is_available() else "mps" if torch.backends.mps.is_available() else "cpu" ) Tensor tensor = torch.randn(2, 3) # tensor info tensor.type() # Data type tensor.size() # Shape of the tensor tensor.shape # Shape of the tensor tensor.dim() # Number of dimensions # type convertions tensor = tensor.cuda() tensor = tensor.cpu() tensor = tensor.float() tensor = tensor.long() torch.set_default_tensor_type(torch.FloatTensor) # Set default tensor type # torch.Tensor <=> np.ndarray ndarray = tensor.cpu().numpy() tensor = torch.from_numpy(ndarray).float() tensor = torch.from_numpy(ndarray.copy()).float() # If ndarray has negative stride # 从只包含一个元素的张量中提取值 value = tensor.item() # torch.Tensor <=> PIL.Image # PyTorch中的张量默认采用N×D×H×W的顺序,并且数据范围在[0, 1],需要进行转置和规范化。 image = PIL.Image.fromarray(torch.clamp(tensor * 255, min=0, max=255 ).byte().permute(1, 2, 0).cpu().numpy()) image = torchvision.transforms.functional.to_pil_image(tensor) # Equivalently way tensor = torch.from_numpy(np.asarray(PIL.Image.open(path)) ).permute(2, 0, 1).float() / 255 tensor = torchvision.transforms.functional.to_tensor(PIL.Image.open(path)) # Equivalently way # np.ndarray <=> PIL.Image image = PIL.Image.fromarray(ndarray.astypde(np.uint8)) ndarray = np.asarray(PIL.Image.open(path)) # reshape tensor.reshape(shape) tensor.permute(0,2,1) # swap axes tensor.flatten() # 展成 1D 向量 tensor.squeeze() # 去掉维数为 1 的的维度 tensor.unsqueeze(dim=0) # 增加维度 # shuffle tensor = tensor[torch.randperm(tensor.size(0))] # Shuffle the first dimension # copy # Operation | New/Shared memory | Still in computation graph | tensor.clone() # | New | Yes | tensor.detach() # | Shared | No | tensor.detach().clone() # | New | No | # concatenate tensor = torch.cat(list_of_tensors, dim=0) tensor = torch.stack(list_of_tensors, dim=0) # one-hot N = tensor.size(0) one_hot = torch.zeros(N, num_classes).long() one_hot.scatter_(dim=1, index=torch.unsqueeze(tensor, dim=1), src=torch.ones(N, num_classes).long()) # non-zero torch.nonzero(tensor) # Index of non-zero elements torch.nonzero(tensor == 0) # Index of zero elements torch.nonzero(tensor).size(0) # Number of non-zero elements torch.nonzero(tensor == 0).size(0) # Number of zero elements # equal torch.allclose(tensor1, tensor2) # float tensor torch.equal(tensor1, tensor2) # int tensor # expand # Expand tensor of shape 64*512 to shape 64*512*7*7. torch.reshape(tensor, (64, 512, 1, 1)).expand(64, 512, 7, 7) # normalize F.normalize(tensor, dim=1) Dataloader from torch.utils.data import TensorDataset, Dataset, DataLoader train_ds = TensorDataset(x_train[:50000], y_train[:50000]) valid_ds = TensorDataset(x_train[50000:], y_train[50000:]) train_dl = DataLoader(train_ds, batch_size=mini_batch, shuffle=True, num_workers=4) valid_dl = DataLoader(valid_ds, batch_size=len(valid_ds)) for xb, yb in train_dl: pass 自定义dataset ...

January 1, 2000

Reinforcement Learning

Reinforcement Learning Github - awesome-rl Github - awesome-deep-rl Github - rl-book Unity ML-Agents Toolkit Github - train_your_own_game_AI Gymnasium Github - CleanRL

January 1, 2000