[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-mims-harvard--TFC-pretraining":3,"tool-mims-harvard--TFC-pretraining":61},[4,18,26,36,44,53],{"id":5,"name":6,"github_repo":7,"description_zh":8,"stars":9,"difficulty_score":10,"last_commit_at":11,"category_tags":12,"status":17},4358,"openclaw","openclaw\u002Fopenclaw","OpenClaw 是一款专为个人打造的本地化 AI 助手，旨在让你在自己的设备上拥有完全可控的智能伙伴。它打破了传统 AI 助手局限于特定网页或应用的束缚，能够直接接入你日常使用的各类通讯渠道，包括微信、WhatsApp、Telegram、Discord、iMessage 等数十种平台。无论你在哪个聊天软件中发送消息，OpenClaw 都能即时响应，甚至支持在 macOS、iOS 和 Android 设备上进行语音交互，并提供实时的画布渲染功能供你操控。\n\n这款工具主要解决了用户对数据隐私、响应速度以及“始终在线”体验的需求。通过将 AI 部署在本地，用户无需依赖云端服务即可享受快速、私密的智能辅助，真正实现了“你的数据，你做主”。其独特的技术亮点在于强大的网关架构，将控制平面与核心助手分离，确保跨平台通信的流畅性与扩展性。\n\nOpenClaw 非常适合希望构建个性化工作流的技术爱好者、开发者，以及注重隐私保护且不愿被单一生态绑定的普通用户。只要具备基础的终端操作能力（支持 macOS、Linux 及 Windows WSL2），即可通过简单的命令行引导完成部署。如果你渴望拥有一个懂你",349277,3,"2026-04-06T06:32:30",[13,14,15,16],"Agent","开发框架","图像","数据工具","ready",{"id":19,"name":20,"github_repo":21,"description_zh":22,"stars":23,"difficulty_score":10,"last_commit_at":24,"category_tags":25,"status":17},3808,"stable-diffusion-webui","AUTOMATIC1111\u002Fstable-diffusion-webui","stable-diffusion-webui 是一个基于 Gradio 构建的网页版操作界面，旨在让用户能够轻松地在本地运行和使用强大的 Stable Diffusion 图像生成模型。它解决了原始模型依赖命令行、操作门槛高且功能分散的痛点，将复杂的 AI 绘图流程整合进一个直观易用的图形化平台。\n\n无论是希望快速上手的普通创作者、需要精细控制画面细节的设计师，还是想要深入探索模型潜力的开发者与研究人员，都能从中获益。其核心亮点在于极高的功能丰富度：不仅支持文生图、图生图、局部重绘（Inpainting）和外绘（Outpainting）等基础模式，还独创了注意力机制调整、提示词矩阵、负向提示词以及“高清修复”等高级功能。此外，它内置了 GFPGAN 和 CodeFormer 等人脸修复工具，支持多种神经网络放大算法，并允许用户通过插件系统无限扩展能力。即使是显存有限的设备，stable-diffusion-webui 也提供了相应的优化选项，让高质量的 AI 艺术创作变得触手可及。",162132,"2026-04-05T11:01:52",[14,15,13],{"id":27,"name":28,"github_repo":29,"description_zh":30,"stars":31,"difficulty_score":32,"last_commit_at":33,"category_tags":34,"status":17},1381,"everything-claude-code","affaan-m\u002Feverything-claude-code","everything-claude-code 是一套专为 AI 编程助手（如 Claude Code、Codex、Cursor 等）打造的高性能优化系统。它不仅仅是一组配置文件，而是一个经过长期实战打磨的完整框架，旨在解决 AI 代理在实际开发中面临的效率低下、记忆丢失、安全隐患及缺乏持续学习能力等核心痛点。\n\n通过引入技能模块化、直觉增强、记忆持久化机制以及内置的安全扫描功能，everything-claude-code 能显著提升 AI 在复杂任务中的表现，帮助开发者构建更稳定、更智能的生产级 AI 代理。其独特的“研究优先”开发理念和针对 Token 消耗的优化策略，使得模型响应更快、成本更低，同时有效防御潜在的攻击向量。\n\n这套工具特别适合软件开发者、AI 研究人员以及希望深度定制 AI 工作流的技术团队使用。无论您是在构建大型代码库，还是需要 AI 协助进行安全审计与自动化测试，everything-claude-code 都能提供强大的底层支持。作为一个曾荣获 Anthropic 黑客大奖的开源项目，它融合了多语言支持与丰富的实战钩子（hooks），让 AI 真正成长为懂上",145895,2,"2026-04-08T11:32:59",[14,13,35],"语言模型",{"id":37,"name":38,"github_repo":39,"description_zh":40,"stars":41,"difficulty_score":32,"last_commit_at":42,"category_tags":43,"status":17},2271,"ComfyUI","Comfy-Org\u002FComfyUI","ComfyUI 是一款功能强大且高度模块化的视觉 AI 引擎，专为设计和执行复杂的 Stable Diffusion 图像生成流程而打造。它摒弃了传统的代码编写模式，采用直观的节点式流程图界面，让用户通过连接不同的功能模块即可构建个性化的生成管线。\n\n这一设计巧妙解决了高级 AI 绘图工作流配置复杂、灵活性不足的痛点。用户无需具备编程背景，也能自由组合模型、调整参数并实时预览效果，轻松实现从基础文生图到多步骤高清修复等各类复杂任务。ComfyUI 拥有极佳的兼容性，不仅支持 Windows、macOS 和 Linux 全平台，还广泛适配 NVIDIA、AMD、Intel 及苹果 Silicon 等多种硬件架构，并率先支持 SDXL、Flux、SD3 等前沿模型。\n\n无论是希望深入探索算法潜力的研究人员和开发者，还是追求极致创作自由度的设计师与资深 AI 绘画爱好者，ComfyUI 都能提供强大的支持。其独特的模块化架构允许社区不断扩展新功能，使其成为当前最灵活、生态最丰富的开源扩散模型工具之一，帮助用户将创意高效转化为现实。",108111,"2026-04-08T11:23:26",[14,15,13],{"id":45,"name":46,"github_repo":47,"description_zh":48,"stars":49,"difficulty_score":32,"last_commit_at":50,"category_tags":51,"status":17},4721,"markitdown","microsoft\u002Fmarkitdown","MarkItDown 是一款由微软 AutoGen 团队打造的轻量级 Python 工具，专为将各类文件高效转换为 Markdown 格式而设计。它支持 PDF、Word、Excel、PPT、图片（含 OCR）、音频（含语音转录）、HTML 乃至 YouTube 链接等多种格式的解析，能够精准提取文档中的标题、列表、表格和链接等关键结构信息。\n\n在人工智能应用日益普及的今天，大语言模型（LLM）虽擅长处理文本，却难以直接读取复杂的二进制办公文档。MarkItDown 恰好解决了这一痛点，它将非结构化或半结构化的文件转化为模型“原生理解”且 Token 效率极高的 Markdown 格式，成为连接本地文件与 AI 分析 pipeline 的理想桥梁。此外，它还提供了 MCP（模型上下文协议）服务器，可无缝集成到 Claude Desktop 等 LLM 应用中。\n\n这款工具特别适合开发者、数据科学家及 AI 研究人员使用，尤其是那些需要构建文档检索增强生成（RAG）系统、进行批量文本分析或希望让 AI 助手直接“阅读”本地文件的用户。虽然生成的内容也具备一定可读性，但其核心优势在于为机器",93400,"2026-04-06T19:52:38",[52,14],"插件",{"id":54,"name":55,"github_repo":56,"description_zh":57,"stars":58,"difficulty_score":10,"last_commit_at":59,"category_tags":60,"status":17},4487,"LLMs-from-scratch","rasbt\u002FLLMs-from-scratch","LLMs-from-scratch 是一个基于 PyTorch 的开源教育项目，旨在引导用户从零开始一步步构建一个类似 ChatGPT 的大型语言模型（LLM）。它不仅是同名技术著作的官方代码库，更提供了一套完整的实践方案，涵盖模型开发、预训练及微调的全过程。\n\n该项目主要解决了大模型领域“黑盒化”的学习痛点。许多开发者虽能调用现成模型，却难以深入理解其内部架构与训练机制。通过亲手编写每一行核心代码，用户能够透彻掌握 Transformer 架构、注意力机制等关键原理，从而真正理解大模型是如何“思考”的。此外，项目还包含了加载大型预训练权重进行微调的代码，帮助用户将理论知识延伸至实际应用。\n\nLLMs-from-scratch 特别适合希望深入底层原理的 AI 开发者、研究人员以及计算机专业的学生。对于不满足于仅使用 API，而是渴望探究模型构建细节的技术人员而言，这是极佳的学习资源。其独特的技术亮点在于“循序渐进”的教学设计：将复杂的系统工程拆解为清晰的步骤，配合详细的图表与示例，让构建一个虽小但功能完备的大模型变得触手可及。无论你是想夯实理论基础，还是为未来研发更大规模的模型做准备",90106,"2026-04-06T11:19:32",[35,15,13,14],{"id":62,"github_repo":63,"name":64,"description_en":65,"description_zh":66,"ai_summary_zh":66,"readme_en":67,"readme_zh":68,"quickstart_zh":69,"use_case_zh":70,"hero_image_url":71,"owner_login":72,"owner_name":73,"owner_avatar_url":74,"owner_bio":75,"owner_company":76,"owner_location":76,"owner_email":77,"owner_twitter":78,"owner_website":79,"owner_url":80,"languages":81,"stars":90,"forks":91,"last_commit_at":92,"license":93,"difficulty_score":10,"env_os":75,"env_gpu":94,"env_ram":94,"env_deps":95,"category_tags":98,"github_topics":99,"view_count":32,"oss_zip_url":76,"oss_zip_packed_at":76,"status":17,"created_at":107,"updated_at":108,"faqs":109,"releases":138},5658,"mims-harvard\u002FTFC-pretraining","TFC-pretraining","Self-supervised contrastive learning for time series via time-frequency consistency","TFC-pretraining 是一款专为时间序列数据设计的自监督对比学习预训练框架。它核心解决了时间序列分析中普遍存在的难题：不同数据集之间因传感器差异、采样不规则或语义不同导致的“域偏移”问题，使得在一个场景训练的模型难以直接迁移到其他场景。\n\n该工具特别适合人工智能研究人员和开发者使用，尤其是那些需要在手势识别、故障检测或癫痫分析等多样化场景中构建高精度模型，但面临标注数据稀缺困境的团队。TFC-pretraining 的独特技术亮点在于其提出的“时频一致性”（Time-Frequency Consistency）理念。受信号处理中傅里叶定理的启发，它认为同一样本在时域和频域的表征应当在潜在空间中彼此靠近。通过在无标签的大规模数据上进行自监督预训练，强制模型学习这种跨域的共同模式，TFC-pretraining 能够提取出极具泛化能力的特征。用户只需将预训练模型在少量特定任务数据上进行微调，即可显著提升下游分类任务的表现，大幅降低了对昂贵标注数据的依赖。","\n# Self-Supervised Contrastive Pre-Training For Time Series via Time-Frequency Consistency\n\n#### Authors: [Xiang Zhang](http:\u002F\u002Fxiangzhang.info\u002F) (xiang.alan.zhang@gmail.com), [Ziyuan Zhao](https:\u002F\u002Fgithub.com\u002Fmims-harvard\u002FRaindrop)(ziyuanzhao@college.harvard.edu), \u003Cbr\u002F>\n####  [Theodoros Tsiligkaridis](https:\u002F\u002Fgithub.com\u002Fmims-harvard\u002FRaindrop)(ttsili@ll.mit.edu), [Marinka Zitnik](https:\u002F\u002Fzitniklab.hms.harvard.edu\u002F) (marinka@hms.harvard.edu)\n\n#### [Project website](https:\u002F\u002Fzitniklab.hms.harvard.edu\u002Fprojects\u002FTF-C\u002F)\n\n#### TF-C Paper: [NeurIPS 2022](https:\u002F\u002Fopenreview.net\u002Fforum?id=OJ4mMfGKLN), [Preprint](https:\u002F\u002Farxiv.org\u002Fabs\u002F2206.08496)\n\n## Overview \n\nThis repository contains eight processed datasets and the codes of developed TF-C pretraining model (along with baselines) for manuscript *Self-Supervised Contrastive Pre-Training For Time Series via Time-Frequency Consistency*. We propose TF-C, a novel pre-training approach for learning generalizable features that can be transferred across different time-series datasets. We evaluate TF-C on eight time series datasets with different sensor measurements and semantic meanings in four real-world application scenarios. The following illustration provides an overview of the idea behind and the broad applicability of our TF-C approach. The idea is shown in **(a)**: given a time series sample, time-based and frequency-based embeddings are made close to each other in a latent time-frequency space. The application scenarios are shown in **(b)**: leveraging TF-C in time series, we can generalize a pre-train models to diverse scenarios such as gesture recognition, fault detection, and seizure analysis.\n\u003C!-- Then we fine-tune the models to a small, problem-specific dataset for performing time series classification tasks. -->\n\n\u003Cp align=\"center\">\n    \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fmims-harvard_TFC-pretraining_readme_699513419ce5.png\" width=\"1000\" align=\"center\">\n\u003C\u002Fp>\n\n\n\n\u003C!-- Please consult our paper for more details about our model and the experiments. -->\n\n\n## Key idea of TF-C\n\nOur model captures the generalizable property of time series, Time-Frequency Consistency (TF-C), in a large pre-training time series dataset. TF-C means the time-based representation and the frequency-based representation, which are learned from the same time series sample, are closer to each other in a joint time-frequency space, and farther apart if the representations are associated with different time series samples. By modeling the TF-C, which is a characteristic unique to time series, the developed model can capture the underlying common pattern in time series and further empower knowledge transfer across different time series datasets. The different time series datasets are compounded by complexity in terms of large variations of temporal dynamics across datasets, varying semantic meaning, irregular sampling, system factors (e.g., different devices or subjects), etc. \nMoreover, the developed model enables self-supervised pre-training (which doesn't demand labels in the pre-training dataset) by adopting contrastive learning framework. Our TF-C approach is shown in the following figure. \n\n\n\u003C!-- See the following figure for an illustration of our TF-C approach. Please see our paper for details on the particular choices of encoder and projector networks, model hyperparameters, and component loss function. -->\n\n\n\u003C!-- Specifically, we adopt contrastive learning in time space to generate a time-based\n67 representation.\nOur model is inspired by the well-known Fourier theorem used extensively in signal processing that states the equivalence between time domain and frequency domain representations of a continuous-time signal. We not only devised augmentations for time series in the time domain and in the frequency domain, but our contrastive loss has an additional term that requires the time- and frequency-domain embeddings be close to each other. Inspired by the triplet loss, we further specify that the similarity between the original time-frequency embedding pairs to be smaller than other possible pairs. We believe our model structure combined with the contrastive loss is sufficiently general to introduce inductive bias to the model that drives transfer learning across different time series domains.  -->\n\n\u003Cp align=\"center\">\n    \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fmims-harvard_TFC-pretraining_readme_1d76b7ed8ba1.png\" width=\"1000\" align=\"center\">\n\u003C\u002Fp>\n\n**Overview of TF-C approach.** our model has four components: a time encoder, a frequency encoder, and two cross-space projectors that map time-based and frequency-based representations, respectively, to the same time-frequency space. Together, the four components provide a way to embed the input time series to the latent time-frequency space such that time-based embedding and frequency-based embedding are close together. \nThe TF-C property is realized by promoting the alignment of time- and frequency-based representations in the latent time-frequency space, providing a vehicle for transferring the well-trained model to a target dataset not seen before.\n\n\n\n## Datasets\n\nWe prepared eight datasets for the four different scenarios that we used to compare our method against the baselines. The scenarios contain electrodiagnostic testing, human daily activity recognition, mechanical fault detection, and physical status monitoring. \n\n### Raw data\n\n(1). **SleepEEG** contains 153 whole-night sleeping Electroencephalography (EEG) recordings that are monitored by sleep cassette. The data is collected from 82 healthy subjects. The 1-lead EEG signal is sampled at 100 Hz. We segment the EEG signals into segments (window size is 200) without overlapping and each segment forms a sample. Every sample is associated with one of the five sleeping patterns\u002Fstages: Wake (W), Non-rapid eye movement (N1, N2, N3) and Rapid Eye Movement (REM). After segmentation, we have 371,055 EEG samples. The [raw dataset](https:\u002F\u002Fwww.physionet.org\u002Fcontent\u002Fsleep-edfx\u002F1.0.0\u002F) is distributed under the Open Data Commons Attribution License v1.0.\n\n(2). **Epilepsy** contains single-channel EEG measurements from 500 subjects. For each subject, the brain activity was recorded for 23.6 seconds. The dataset was then divided and shuffled (to mitigate sample-subject association) into 11,500 samples of 1 second each, sampled at 178 Hz. The raw dataset features 5 different classification labels corresponding to different status of the subject or location of measurement - eyes open, eyes closed, EEG measured in healthy brain region, EEG measured where the tumor was located, and, finally, the subject experiencing seizure episode. To emphasize the distinction between positive and negative samples in terms of epilepsy, We merge the first 4 classes into one and each time series sample has a binary label describing if the associated subject is experiencing seizure or not. There are 11,500 EEG samples in total. To evaluate the performance of pre-trained model on small fine-tuning dataset, we choose a tiny set (60 samples; 30 samples for each class) for fine-tuning and assess the model with a validation set (20 samples; 10 sample for each class). The model with best validation performance is use to make prediction on test set (the remaining 11,420 samples). The [raw dataset](https:\u002F\u002Frepositori.upf.edu\u002Fhandle\u002F10230\u002F42894) is distributed under the Creative Commons License (CC-BY) 4.0.\n\n(3), (4). **FD-A** and **FD-B** are subsets taken from the **FD** dataset, which is gathered from an electromechanical drive system that monitors the condition of rolling bearings and detects damages in them. There are four subsets of data collected under various conditions, whose parameters include rotational speed, load torque, and radial force. Each rolling bearing can be undamaged, inner damaged, and outer damaged, which leads to three classes in total. We denote the subsets corresponding to condition A and condition B as Faulty Detection Condition A (**FD-A**) and Faulty Detection Condition B (**FD-B**) , respectively. Each original recording has a single channel with sampling frequency of 64k Hz and lasts 4 seconds. To deal with the long duration, we follow the procedure described by Eldele et al., that is, we use sliding window length of 5,120 observations and a shifting length of either 1,024 or 4,096 to make the final number of samples relatively balanced between classes. The [raw dataset](https:\u002F\u002Fmb.uni-paderborn.de\u002Fen\u002Fkat\u002Fmain-research\u002Fdatacenter\u002Fbearing-datacenter\u002Fdata-sets-and-download) is distributed under the Creative Commons Attribution-Non Commercial 4.0 International License.\n\n(5). **HAR** contains recordings of 30 health volunteers performing six daily activities such as walking, walking upstairs, walking downstairs, sitting, standing, and laying. The prediction labels are the six activities. The wearable sensors on a smartphone measure triaxial linear acceleration and triaxial angular velocity at 50 Hz. After preprocessing and isolating out gravitational acceleration from body acceleration, there are nine channels in total. To line up the semantic domain with the channels in the dataset use during fine-tuning **Gesture** we only use the three channels of body linear accelerations. The [raw dataset](https:\u002F\u002Farchive.ics.uci.edu\u002Fml\u002Fdatasets\u002FHuman+Activity+Recognition+Using+Smartphones) is distributed AS-IS and no responsibility implied or explicit can be addressed to the authors or their institutions for its use or misuse. Any commercial use is prohibited.\n\n(6). **Gesture** contains accelerometer measurements of eight simple gestures that differed based on the paths of hand movement. The eight gestures are: hand swiping left, right, up, down, hand waving in a counterclockwise circle, or in clockwise circle, hand waving in a square, and waving a right arrow. The classification labels are those eight different types of gestures. The original paper reports inclusion of 4,480 gesture measurements, but through UCR Database we were only able to recover 440 measurements. The dataset is balanced with 55 samples each class and is of a suitable size for our purpose of fine-tuning experiments. Sampling frequency is not explicitly reported in the original paper but is presumably 100 Hz. The dataset uses three channels corresponding to three coordinate directions of linear acceleration. The [raw dataset](http:\u002F\u002Fwww.timeseriesclassification.com\u002Fdescription.php?Dataset=UWaveGestureLibrary) is publicly available.\n\n(7). **ECG** is taken as a subset from the 2017 PhysioNet Challenge that focuses on ECG recording classification. The single lead ECG measures four different underlying conditions of cardiac arrhythmias. More specifically, these classes correspond to the recordings of normal sinus rhythm, atrial fibrillation (AF), alternative rhythm, or others (too noisy to be classified). The recordings are sampled at 300 Hz. Furthermore, the dataset is imbalanced, with much fewer samples from the atrial fibrillation and noisy classes out of all four. To preprocess the dataset, we use the code from the CLOCS paper, which applied fixed-length window of 1,500 observations to divide up the long recordings into short samples of 5 seconds in duration that is still physiologically meaningful. The [raw dataset](https:\u002F\u002Fphysionet.org\u002Fcontent\u002Fchallenge-2017\u002F1.0.0\u002F) is distributed under the Open Data Commons Attribution License v1.0.\n\n(8). Electromyograms (EMG) measures muscle responses as electrical activity to neural stimulation, and they can be used to diagnose certain muscular dystrophies and neuropathies. **EMG** consists of single-channel EMG recording from the tibialis anterior muscle of three volunteers that are healthy, suffering from neuropathy, and suffering from myopathy, respectively. The recordings are sampled with the frequency of 4K Hz. Each patient, i.e., their disorder, is a separate classification category. Then the recordings are split into time series samples using a fixed-length window of 1,500 observations. The [raw dataset](https:\u002F\u002Fphysionet.org\u002Fcontent\u002Femgdb\u002F1.0.0\u002F) is distributed under the Open Data Commons Attribution License v1.0.\n\nThe following table summarizes the statistics of all these eight datasets:\n\n| Scenario # |              | Dataset      | # Samples    | # Channels | # Classes | Length | Freq (Hz) |\n| ---------- | ------------ | ------------ | ------------ | ---------- | --------- | ------ | --------- |\n| 1          | Pre-training | **SleepEEG** | 371,055      | 1          | 5         | 200    | 100       |\n|            | Fine-tuning  | **Epilepsy** | 60\u002F20\u002F11,420 | 1          | 2         | 178    | 174       |\n| 2          | Pre-training | **FD-A**     | 8,184        | 1          | 3         | 5,120  | 64K       |\n|            | Fine-tuning  | **FD-B**     | 60\u002F21\u002F13,559 | 1          | 3         | 5,120  | 64K       |\n| 3          | Pre-training | **HAR**      | 10,299       | 9          | 6         | 128    | 50        |\n|            | Fine-tuning  | **Gesture**  | 320\u002F120\u002F120  | 3          | 8         | 315    | 100       |\n| 4          | Pre-training | **ECG**      | 43,673       | 1          | 4         | 1,500  | 300       |\n|            | Fine-tuning  | **EMG**      | 122\u002F41\u002F41    | 1          | 3         | 1,500  | 4,000     |\n\n### Processed data\n\nWe explain the data preprocessing and highlight some steps here for clarity. More details can be found in our paper appendix. In summary, our data-processing consists of two stages. First, we segmented time series recordings if they are too long. For fine-tuning (target) datasets, we split the dataset into train, validation, and test portions. We took care to assign all samples belonging to a single recording to one partition only whenever that is possible, to avoid leaking data from the test set into the training set, but for pre-processed datasets like Epilepsy this is not possible. The train: val ratio is at about 3: 1 and we used balanced number of samples for each class whenever possible. All remaining samples not included in the train and validation partitions are used in the test partition to better estimate the performance metrics of the models. After the first stage, we produced three *.pt* (pytorch format) files corresponding to the three partitions for each dataset. Each file contains a dictionary with keys of `samples` and `labels` and corresponding values of torch tensors storing the data, respectively. For samples, the tensor dimensions correspond to the number of samples, number of channels, and, finally, the length of each time series sample. This is the standard format that can be directly read by the TS-TCC model as well as our TF-C implementation. \n\u003C!-- These preprocessed datasets can be conveniently downloaded from (????) or viaa script (???) into the datasets folder in this repo.  -->\n\nThe second step consists of converting, for each dataset, from the three .pt files, to the accepted input format for each of the baseline models and placing them in the correct directories relative to the script that handles the pre-training and fine-tuning process. We have prepared simple scripts for these straightforward tasks but did not automate them. To further reduce the clutter of files in the repo, we have chosen to omit them from the baseline folders. Also, note that in the second experiment of one-to-many pre-training, the fine-tuning datasets are further clipped to have the same length as the sleepEEG dataset. \n\u003C!-- The pre-processing scripts are available upon reasonable request. -->\n\n**Step one** \nThe processed datasets can be manually downloaded at the following links. \n\n- wget -O SleepEEG.zip https:\u002F\u002Ffigshare.com\u002Fndownloader\u002Farticles\u002F19930178\u002Fversions\u002F1\n- wget -O Epilepsy.zip https:\u002F\u002Ffigshare.com\u002Fndownloader\u002Farticles\u002F19930199\u002Fversions\u002F2 \n- wget -O FD-A.zip https:\u002F\u002Ffigshare.com\u002Fndownloader\u002Farticles\u002F19930205\u002Fversions\u002F1\n- wget -O FD-B.zip https:\u002F\u002Ffigshare.com\u002Fndownloader\u002Farticles\u002F19930226\u002Fversions\u002F1\n- wget -O HAR.zip https:\u002F\u002Ffigshare.com\u002Fndownloader\u002Farticles\u002F19930244\u002Fversions\u002F1\n- wget -O Gesture.zip https:\u002F\u002Ffigshare.com\u002Fndownloader\u002Farticles\u002F19930247\u002Fversions\u002F1\n- wget -O ECG.zip https:\u002F\u002Ffigshare.com\u002Fndownloader\u002Farticles\u002F19930253\u002Fversions\u002F1\n- wget -O EMG.zip https:\u002F\u002Ffigshare.com\u002Fndownloader\u002Farticles\u002F19930250\u002Fversions\u002F1\n\nThen you have to place the files inside the corresponding folder under `data\u002Fdataset_name` (such as `data\u002FSleepEEG`):\n\n**The well-processed datasets will be released (in FigShare) after acceptance. **\n\n\nAlternatively, you can use the `download_datasets.sh` script to automatically download and decompress all datasets into the respective directories. This immediately finishes the first step of preprocessing.\n\n**Step two**\nNow we explain in detail the second step. To begin with, TS-TCC and TS-SD (along with our TF-C model), as implemented under the TS-TCC codebase, can directly take in the datasets downloaded from the previous step. All that remains is to create the corresponding subdirectories at `TS-TCC\u002Fdata\u002Fdataset_name` and put in the datasets inside. This is handled by the shell script `data_processing\u002FTS-TCC.sh` which creates the folders and soft links that alias to the downloaded files.\n\nFor TS2Vec, it uses exactly the same kind of `{train,test}_{input,output}.npy` files as Mixing-up, so we will just process our downloaded datasets once and use them for these two models. The only difference in data format is the tensors for labels are two dimensional, so we have to insert an axis to each such tensor. This is handled in `data_processing\u002FMixing-up.py` and we can then run `data_processing\u002FTS2vec.sh` to create aliases to the processed files.\n\nNext, for CLOCS, we need to make a more complicated nested dictionary holding the time series and labels. Also, a time series sample is stored as a two dimensional tensor now, by eliminating the channel dimension, because CLOCS assumes that we discard channel information during data preprocessing. Again, the final datasets should be placed in the correct location, which is also in the format of `CLOCS\u002Fdata\u002Fdataset_name`. However, due to aliasing issues, the name to be used may not align with how we named the datasets in the paper. Please use the python script `data_processing\u002FCLOCS.py` to do the above steps automatically.\n\nFinally, for SimCLR, we do not have a datafolder but directly place files under `SimCLR\u002Fdataset_name`. For the data itself, we note that the tensor storing time series have the second and third dimension, corresponding to channels and observations, swapped, relative to our starting files. Also, the labels cannot be numeric but have to be in one-hot format. These are handled in the `data_processing\u002FSimCLR.py` script for convenience.\n\nOf course, we also provide the shortcut script for doing all the steps above, by directly running `process_all.sh` from the root directory of the git repository. Make sure you are in the correct environment as specified by the `baseline_requirements.yml` before running the scripts.\n\n\n## Experimental setups\n\nWe evaluated our model in two different settings and in comparison with eight baselines. The baselines include six state-of-the-art models that can be used for transfer learning in time series and two non-pre-training models ( a non-DL method (KNN in this case) and a randomly initialized model). The two different settings are:\n\n**Setting 1: One-to-one pre-training.** We pre-trained a model on *one* pre-training dataset and use it for fine-tuning on *one* target dataset only. We tested the proposed model in four independent scenarios: neurological stage detection, mechanical device diagnosis, activity recognition, and physical status monitoring.  For example, in Scenario 1 (neurological stage detection), pre-training is done on SleepEEG and fine-tuning on Epilepsy. While both datasets describe a single-channel EEG, the signals are from different channels\u002Fpositions on the scalp, monitor different physiology (sleep vs. epilepsy), and are collected from different patients. This setting simulates a wide range of practical scenarios where transfer learning may be useful in practice, when there's a domain gap and the fine-tuning dataset is small.\n\n**Setting 2: One-to-many pre-training.** We pre-trained a model using *one* dataset followed by fine-tuning on *multiple* target datasets independently without pre-training from scratch. We chose SleepEEG for pre-training because of the large dataset size and complex temporal dynamics. We fine-tune on Epilepsy, FD-B, and EMG from the other three scenarios. The domain gaps are larger between the pre-training dataset and the three fine-tuning datasets this time, so this setting tests the generality of our model for transfer learning. \n\n\u003C!-- **Setting 3: Ablation study.** To evaluate the relative importance of the different components of our model during pre-training, we modified or simplified the loss function and repeated the experiment. We also compared the performance difference between partial and full fine-tuning. For more details about our ablation study, please consult Appendix Table 7 in our paper. -->\n\n\n## Requirements\n\nTF-C has been tested using Python >=3.5.\n\nFor the baselines, we have not managed to unify the environments due to the large divergence in original baseline implementations. So you need to build three different environments to cover all six DL baselines. For ts2vec, use ts2vec_requirements.yml. For SimCLR, because Tang et al. used TensorFlow framework, please use simclr_requirements.yml. For the other four baselines, use `baseline_requirements.yml`. To use these files to install dependencies for this project via Conda, run the following command:\n\n`conda env create -f XXX_requirements.yml `\n\n## Running the code\n\n**Reproduce our TF-C** Please download the processed datasets to folder `code\u002Fdata\u002FSleepEEG`. Make sure the folder name is the same with the dataset name. There are three key parameters: *training_mode* has two options *pre_train* and *fine_tune_test*; *pretrain_dataset* has four options *SleepEEG*, *FD_A*, *HAR*, and *ECG*; *target_dataset* has four options *Epilepsy*, *FD_B*, *Gesture*, and *EMG*. The hyper-parameters of the models can be found in the configure file in folder `config_files`. For example, when pre-train a model on SleepEEG and fine-tune it on Epilepsy, please run: \n\n`python main.py --training_mode pre_train --pretrain_dataset SleepEEG --target_dataset Epilepsy`\n\n`python main.py --training_mode fine_tune_test --pretrain_dataset SleepEEG --target_dataset Epilepsy`\n\n**Reproduce baselines** You are advised to run the models from the corresponding folders under `code\u002Fbaselines\u002F` using the command-line patterns described by the original authors' `README  .md` files whenever possible. We note that in the case of Mixing-up and SimCLR, pre-training and fine-tuning are done by directly running `train_model.py` and `finetune_model.py` without passing in arguments. Similarly, for CLOCS, one must manually modify the hyperparameters to the training procedure inside the main file (  `run_experiments.py` in this case). Please reach out to the original authors of these baselines if you have any questions about setting these hyperparameters in their models. Finally, for each baseline, on different pairs of datasets, the performance of transfer learning can vary depending on the hyperparameter choices. We have manually experimented with them and chose the combinations that gave the best performance while keeping the model complexity of different baselines comparable. We include tables describing the specific combinations of hyperparameters we used for different datasets whenever necessary, in the corresponding folder for the different baselines so that reproducing our result is made possible. Please note some baselines are designed for representation learning (instead of pre-training) of time series, we use these baselines in the same setups as our model to make results comparable.\n\n## Citation\n\nIf you find *TF-C* useful for your research, please consider citing this paper:\n\n````\n```\n@inproceedings{zhang2022self,\ntitle = {Self-Supervised Contrastive Pre-Training For Time Series via Time-Frequency Consistency},\nauthor = {Zhang, Xiang and Zhao, Ziyuan and Tsiligkaridis, Theodoros and Zitnik, Marinka},\nbooktitle = {Proceedings of Neural Information Processing Systems, NeurIPS},\nyear      = {2022}\n}\n```\n````\n\n## Updated Jan. 2023\n\nWe updated the implementation the proposed TF-C model on the following aspects.\n\n1. Fixed bugs, cleaned the codes, and added comments for better understanding. The newly uploaded TF-C code is at path `TFC-pretraining\u002Fcode\u002FTFC`. All the necessary files to run it are provided in the folder. \n2. For the contrastive encoders (in both time and frequency domains), we replaced the 3 layers of CNN blocks with 2 layers of Transformer. We noticed that the performance is not improved (even with a slight decrease) but the stability is getting better. \n3. For the downstream classifier, we added a KNN classifier in parallel with the original MLP (2-layer) classifier. In preliminary experiments, we noticed that the performance of MLP varies across different setups and hyper-parameter settings. Thus, in this version, we provide two classifiers: 2-layer MLP and KNN (K=5). However, the reasons hidden behind the performance variance are still unknown, which needs further studies. \n4. For better reproduction, we hereby provided an example of a pre-trained model. The model weights can be found in path `TFC-pretraining\u002Fcode\u002Fexperiments_logs\u002FSleepEEG_2_Epilepsy\u002Frun1\u002Fpre_train_seed_42_2layertransformer\u002Fsaved_models\u002Fckp_last.pt`. The model path is identical to the one used in code, so you may clone\u002Fdownload this whole repo and directly run the 'TFC-pretraining\u002Fcode\u002FTFC\u002Fmain.py' file. \n    - This model is pretrained on the scenario: SleepEEG to Epilepsy (in this update, all the debugs are based on this setup). In specific, setting the training_mode as `pre_train` and pretrain_dataset as `SleepEEG`. In SleepEEG_Configs.py, all the hyper-parameters are unchanged, in specific, lr=0.0005, epoch number as 200 (200 for pretraining while 20 for finetuning). We set the random seed as 42.\n    - In finetuning on Epilepsy (lr= 0.0005, epoch=20, batchsize=60), the finetuning set is still 60 samples (30 positive + 30 negative). There are 20 validation and 11420 test samples. But we have resplit the Epilepsy dataset (i.e., regenerated the 60 finetuning set) to test the stability of the model. The code for re-splitting is available at `TFC-pretraining\u002Fcode\u002FTFC\u002FData_split.py` and the split dataset is uploaded to this repo `TFC-pretraining\u002Fdatasets\u002FEpilepsy\u002F` (it is also synchronized to Figshare). \n    - In such a seting, with the help of TFC, the best test performance on finetuning set is ~0.88 on F1 (achieved by MLP which beats KNN) while only ~0.60 without TFC pretraining. *Please note, for quick debugging, the model is pretrained on a subset of SleepEEG (1280 samples which are only \u003C1% of the whole dataset).* Thus, we believe there's a large space to further boost the performance with more pretraining samples.\n5. We'd like to share more ideas that may improve the TF-C framework in follow-up works. \n    - The 2-layer transformer could be modified based on the specific task (e.g., adding more layers for complex time series). The polishing on the backbone can be helpful. BTW, I didn't tune the hyper-parameters after switching to Transformer, a better hyperparameter setting (e.g., the number of layers, the dimension of Transformer, the dimension of the MLP hidden layer, etc.) might be helpful. \n    - Use different architectures in time-based and frequency-based encoders. As the signals' properties in the frequency domain is very different with time domain, a dedicated encoder architecture can be adopted to better capture the information.\n    - Explore more augmentations in frequency domain. Now, we used adding or removing frequency components,  so that designing more perturbations (like bandpass filtering) is a promising way. \n    - In the frequency domain, we only leveraged the magnitude information, however, the phase is also very important. So, an important future topic will fully exploit the information in the frequency domain. \n    - Better projection. Now, we project the time- and frequency-based embeddings to a shared time-frequency domain. The current projectors' structure is a 2-layer MLP which is kind of simple. More powerful and helpful projecting methods are welcomed. \n    - More ideas may be added.\n\n\n## Miscellaneous\n\nPlease send any questions you might have about the code and\u002For the algorithm to \u003Cxiang.alan.zhang@gmail.com>. \n\n\n\n## License\n\nTF-C codebase is released under the MIT license.\n\n","# 基于时频一致性的自监督对比预训练用于时间序列\n\n#### 作者：[张翔](http:\u002F\u002Fxiangzhang.info\u002F) (xiang.alan.zhang@gmail.com)、[赵子源](https:\u002F\u002Fgithub.com\u002Fmims-harvard\u002FRaindrop)(ziyuanzhao@college.harvard.edu)，\u003Cbr\u002F>\n####  [西奥多罗斯·齐利加里迪斯](https:\u002F\u002Fgithub.com\u002Fmims-harvard\u002FRaindrop)(ttsili@ll.mit.edu)、[马林卡·齐特尼克](https:\u002F\u002Fzitniklab.hms.harvard.edu\u002F) (marinka@hms.harvard.edu)\n\n#### [项目网站](https:\u002F\u002Fzitniklab.hms.harvard.edu\u002Fprojects\u002FTF-C\u002F)\n\n#### TF-C 论文：[NeurIPS 2022](https:\u002F\u002Fopenreview.net\u002Fforum?id=OJ4mMfGKLN)、[预印本](https:\u002F\u002Farxiv.org\u002Fabs\u002F2206.08496)\n\n## 概述 \n\n本仓库包含八个经过处理的数据集，以及为论文《基于时频一致性的自监督对比预训练用于时间序列》开发的 TF-C 预训练模型代码（连同基线模型）。我们提出了 TF-C，这是一种新颖的预训练方法，用于学习可跨不同时间序列数据集迁移的通用特征。我们在八个具有不同传感器测量和语义含义的时间序列数据集上，针对四个真实世界应用场景进行了评估。下图概述了我们的 TF-C 方法背后的思想及其广泛的适用性。该思想如 **(a)** 所示：给定一个时间序列样本，在潜在的时频空间中，基于时间的嵌入与基于频率的嵌入被拉近。应用场景如 **(b)** 所示：通过在时间序列中利用 TF-C，我们可以将预训练模型泛化到手势识别、故障检测和癫痫发作分析等多种场景。\n\u003C!-- 然后我们将这些模型微调到特定问题的小型数据集上，以执行时间序列分类任务。 -->\n\n\u003Cp align=\"center\">\n    \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fmims-harvard_TFC-pretraining_readme_699513419ce5.png\" width=\"1000\" align=\"center\">\n\u003C\u002Fp>\n\n\n\n\u003C!-- 更多关于我们的模型和实验细节，请参阅我们的论文。 -->\n\n\n## TF-C 的核心思想\n\n我们的模型在大规模预训练时间序列数据集中捕捉了时间序列的可泛化特性——时频一致性（TF-C）。所谓时频一致性，是指从同一时间序列样本中学习到的基于时间和基于频率的表示，在联合时频空间中彼此更接近；而如果这些表示来自不同的时间序列样本，则会更加远离。通过建模这种专属于时间序列的特性，所开发的模型能够捕捉时间序列中的底层共性模式，并进一步促进知识在不同时间序列数据集之间的迁移。这些不同的时间序列数据集往往存在复杂性，例如各数据集之间的时间动态变化巨大、语义含义各异、采样不规则、系统因素（如不同设备或受试者）等。\n\n此外，所开发的模型采用对比学习框架，实现了自监督预训练（无需预训练数据集中的标签）。我们的 TF-C 方法如下图所示。\n\n\n\u003C!-- 下图展示了我们的 TF-C 方法。有关编码器和投影器网络的具体选择、模型超参数以及组件损失函数的详细信息，请参阅我们的论文。 -->\n\n\n\u003C!-- 具体而言，我们在时间域中采用对比学习来生成基于时间的\n67 表示。\n我们的模型受到信号处理领域广泛应用的傅里叶定理启发，该定理指出连续时间信号在时域和频域上的表示是等价的。我们不仅设计了时间域和频域中的数据增强方法，还为对比损失增加了一项约束，要求时域和频域的嵌入彼此靠近。受三元组损失的启发，我们进一步规定原始时频嵌入对之间的相似度应低于其他可能的嵌入对。我们认为，我们的模型结构结合对比损失，足以引入归纳偏置，从而推动模型在不同时间序列领域之间的迁移学习。 -->\n\n\u003Cp align=\"center\">\n    \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fmims-harvard_TFC-pretraining_readme_1d76b7ed8ba1.png\" width=\"1000\" align=\"center\">\n\u003C\u002Fp>\n\n**TF-C 方法概述。** 我们的模型由四个组件组成：时间编码器、频率编码器，以及两个跨空间投影器，分别将基于时间的表示和基于频率的表示映射到同一个时频空间。这四个组件共同作用，可以将输入的时间序列嵌入到潜在的时频空间中，使基于时间的嵌入与基于频率的嵌入相互靠近。\n通过促进潜在时频空间中基于时间和基于频率的表示对齐，TF-C 特性得以实现，从而为将训练好的模型迁移到未曾见过的目标数据集提供了途径。\n\n\n\n## 数据集\n\n我们准备了八个数据集，用于四个不同的场景，以此比较我们的方法与基线模型。这些场景包括电诊断测试、人类日常活动识别、机械故障检测和身体状态监测。\n\n### 原始数据\n\n(1). **SleepEEG** 包含 153 个整夜睡眠脑电图（EEG）记录，由睡眠监测仪采集。数据来自 82 名健康受试者。单导联 EEG 信号以 100 Hz 采样率采集。我们将 EEG 信号分割成无重叠的片段（窗口大小为 200），每个片段构成一个样本。每个样本对应五种睡眠模式\u002F阶段之一：清醒（W）、非快速眼动睡眠（N1、N2、N3）和快速眼动睡眠（REM）。分割后，我们得到 371,055 个 EEG 样本。该 [原始数据集](https:\u002F\u002Fwww.physionet.org\u002Fcontent\u002Fsleep-edfx\u002F1.0.0\u002F) 依据开放数据共享署名许可协议 v1.0 发布。\n\n(2). **癫痫** 数据集包含500名受试者的单通道脑电图测量数据。对于每位受试者，其脑活动被记录了23.6秒。随后，数据集被分割并打乱（以减少样本与受试者之间的关联），形成11,500个1秒长的样本，采样频率为178 Hz。原始数据集包含5个不同的分类标签，分别对应受试者的不同状态或测量位置：睁眼、闭眼、健康脑区的脑电图、肿瘤所在区域的脑电图，以及正在发作癫痫的受试者。为了突出癫痫阳性与阴性样本之间的区别，我们将前4类合并为一类，每个时间序列样本都带有二元标签，用于描述相关受试者是否正在发作癫痫。整个数据集共有11,500个脑电图样本。为了评估预训练模型在小规模微调数据集上的性能，我们选择了一个小型子集（60个样本；每类30个）进行微调，并使用验证集（20个样本；每类10个）对模型进行评估。表现最佳的模型将用于对测试集（剩余的11,420个样本）进行预测。[原始数据集](https:\u002F\u002Frepositori.upf.edu\u002Fhandle\u002F10230\u002F42894) 依据知识共享署名4.0协议（CC-BY）发布。\n\n(3), (4). **FD-A** 和 **FD-B** 是从 **FD** 数据集中提取的子集，该数据集来自一个机电驱动系统，用于监测滚动轴承的状态并检测其损坏情况。数据集包含四个在不同工况下采集的子集，这些工况的参数包括转速、负载扭矩和径向力。每个滚动轴承可能处于完好、内圈损坏或外圈损坏状态，因此总共分为三类。我们分别将对应工况A和工况B的子集称为故障检测工况A（**FD-A**）和故障检测工况B（**FD-B**）。每段原始记录为单通道，采样频率为64 kHz，持续时间为4秒。为处理较长的时长，我们遵循Eldele等人的方法，即使用5,120个观测值的滑动窗口，步长分别为1,024或4,096，以使最终各分类下的样本数量相对均衡。[原始数据集](https:\u002F\u002Fmb.uni-paderborn.de\u002Fen\u002Fkat\u002Fmain-research\u002Fdatacenter\u002Fbearing-datacenter\u002Fdata-sets-and-download) 依据知识共享署名-非商业性使用4.0国际许可协议发布。\n\n(5). **HAR** 数据集包含30名健康志愿者执行六种日常活动的记录，包括步行、上楼梯、下楼梯、坐下、站立和躺下。预测标签即为这六种活动。智能手机上的可穿戴传感器以50 Hz的频率测量三轴线加速度和三轴角速度。经过预处理并从身体加速度中分离出重力加速度后，共得到九个通道。为了使语义域与微调实验中使用的**Gesture**数据集中的通道保持一致，我们仅保留身体线加速度的三个通道。[原始数据集](https:\u002F\u002Farchive.ics.uci.edu\u002Fml\u002Fdatasets\u002FHuman+Activity+Recognition+Using+Smartphones) 按“原样”提供，作者及其所属机构对其使用或误用不承担任何明示或暗示的责任。禁止任何商业用途。\n\n(6). **Gesture** 数据集包含八种简单手势的加速度计测量数据，这些手势根据手部运动轨迹的不同而有所区分。这八种手势是：左手划动、右手划动、向上划动、向下划动、逆时针划圆、顺时针划圆、划方形以及划右箭头。分类标签即为这八种不同类型的手势。原始论文报告称包含了4,480次手势测量，但通过UCR数据库我们仅恢复了440次测量。该数据集每类有55个样本，分布均衡，且规模适于我们的微调实验目的。原始论文未明确报告采样频率，但推测为100 Hz。数据集使用三个通道，分别对应线加速度的三个坐标方向。[原始数据集](http:\u002F\u002Fwww.timeseriesclassification.com\u002Fdescription.php?Dataset=UWaveGestureLibrary) 公开可用。\n\n(7). **ECG** 是2017年PhysioNet挑战赛的一个子集，该挑战赛专注于心电图记录的分类。单导联心电图用于测量四种不同的心脏节律异常状况。具体而言，这些类别对应于正常窦性心律、心房颤动（AF）、交替性心律以及其他（噪声过大无法分类）的记录。记录的采样频率为300 Hz。此外，数据集存在不平衡问题，心房颤动和噪声过大的类别样本数量远少于其他两类。为了预处理数据集，我们采用CLOCS论文中的代码，即使用固定长度为1,500个观测值的窗口，将长时间记录分割成5秒钟的短样本，这些样本仍具有生理意义。[原始数据集](https:\u002F\u002Fphysionet.org\u002Fcontent\u002Fchallenge-2017\u002F1.0.0\u002F) 依据开放数据知识共享署名许可证v1.0发布。\n\n(8). 肌电图（EMG）用于测量肌肉在神经刺激下的电活动响应，可用于诊断某些肌营养不良症和神经病变。**EMG** 数据集由三名志愿者的胫前肌单通道肌电图记录组成，这三名志愿者分别健康、患有神经病变和患有肌病。记录的采样频率为4 kHz。每位患者及其所患疾病被视为一个独立的分类类别。随后，记录被分割成时间序列样本，使用固定长度为1,500个观测值的窗口。[原始数据集](https:\u002F\u002Fphysionet.org\u002Fcontent\u002Femgdb\u002F1.0.0\u002F) 依据开放数据知识共享署名许可证v1.0发布。\n\n下表总结了所有八个数据集的统计信息：\n\n| 场景编号 |              | 数据集      | 样本数量    | 通道数 | 类别数 | 长度 | 频率 (Hz) |\n| ---------- | ------------ | ------------ | ------------ | ---------- | --------- | ------ | --------- |\n| 1          | 预训练       | **SleepEEG** | 371,055      | 1          | 5         | 200    | 100       |\n|            | 微调         | **Epilepsy** | 60\u002F20\u002F11,420 | 1          | 2         | 178    | 174       |\n| 2          | 预训练       | **FD-A**     | 8,184        | 1          | 3         | 5,120  | 64K       |\n|            | 微调         | **FD-B**     | 60\u002F21\u002F13,559 | 1          | 3         | 5,120  | 64K       |\n| 3          | 预训练       | **HAR**      | 10,299       | 9          | 6         | 128    | 50        |\n|            | 微调         | **Gesture**  | 320\u002F120\u002F120  | 3          | 8         | 315    | 100       |\n| 4          | 预训练       | **ECG**      | 43,673       | 1          | 4         | 1,500  | 300       |\n|            | 微调         | **EMG**      | 122\u002F41\u002F41    | 1          | 3         | 1,500  | 4,000     |\n\n\n\n### 处理后的数据\n\n我们在此详细说明数据预处理过程，并突出一些关键步骤以确保清晰。更多细节请参阅论文附录。总体而言，我们的数据处理分为两个阶段。首先，对于过长的时间序列记录，我们会将其分段。对于微调（目标）数据集，我们将数据集划分为训练集、验证集和测试集。在可能的情况下，我们会尽量将属于同一记录的所有样本分配到同一个分区，以避免测试集中的数据泄露到训练集中；但对于已预处理的数据集，如癫痫数据集，则无法做到这一点。训练集与验证集的比例约为3:1，并且我们尽可能为每个类别分配均衡的样本数量。所有未包含在训练和验证分区中的剩余样本都会被放入测试分区，以便更准确地评估模型的性能指标。完成第一阶段后，我们为每个数据集生成了三个对应于三个分区的*.pt*文件（PyTorch格式）。每个文件包含一个字典，键分别为`samples`和`labels`，对应的值则是存储数据的PyTorch张量。对于样本，张量的维度分别对应样本数量、通道数以及每个时间序列样本的长度。这是TS-TCC模型以及我们的TF-C实现可以直接读取的标准格式。\n\u003C!-- 这些预处理后的数据集可以方便地从(????)下载，或通过脚本(???)导入到本仓库的datasets文件夹中。 -->\n\n第二步是将每个数据集的三个*.pt*文件转换为各基线模型所接受的输入格式，并将其放置到与负责预训练和微调流程的脚本相对应的正确目录中。我们为此准备了简单的脚本，但并未将其自动化。为了进一步减少仓库中的文件杂乱，我们选择不在基线文件夹中包含这些脚本。此外，请注意，在一对多预训练的第二个实验中，微调数据集会被进一步裁剪，使其长度与sleepEEG数据集相同。\n\u003C!-- 预处理脚本可根据合理请求提供。 -->\n\n**第一步**\n处理后的数据集可以通过以下链接手动下载。\n\n- wget -O SleepEEG.zip https:\u002F\u002Ffigshare.com\u002Fndownloader\u002Farticles\u002F19930178\u002Fversions\u002F1\n- wget -O Epilepsy.zip https:\u002F\u002Ffigshare.com\u002Fndownloader\u002Farticles\u002F19930199\u002Fversions\u002F2 \n- wget -O FD-A.zip https:\u002F\u002Ffigshare.com\u002Fndownloader\u002Farticles\u002F19930205\u002Fversions\u002F1\n- wget -O FD-B.zip https:\u002F\u002Ffigshare.com\u002Fndownloader\u002Farticles\u002F19930226\u002Fversions\u002F1\n- wget -O HAR.zip https:\u002F\u002Ffigshare.com\u002Fndownloader\u002Farticles\u002F19930244\u002Fversions\u002F1\n- wget -O Gesture.zip https:\u002F\u002Ffigshare.com\u002Fndownloader\u002Farticles\u002F19930247\u002Fversions\u002F1\n- wget -O ECG.zip https:\u002F\u002Ffigshare.com\u002Fndownloader\u002Farticles\u002F19930253\u002Fversions\u002F1\n- wget -O EMG.zip https:\u002F\u002Ffigshare.com\u002Fndownloader\u002Farticles\u002F19930250\u002Fversions\u002F1\n\n然后需要将这些文件放置到`data\u002Fdataset_name`下的相应文件夹中（例如`data\u002FSleepEEG`）：\n\n**处理完善的数据集将在论文接收后发布（在FigShare上）。**\n\n\n或者，您也可以使用`download_datasets.sh`脚本自动下载并解压所有数据集到各自的目录中，从而立即完成预处理的第一步。\n\n**第二步**\n现在我们详细说明第二步。首先，TS-TCC和TS-SD（以及我们的TF-C模型）作为TS-TCC代码库的一部分，可以直接使用上一步下载的数据集。剩下的工作只是在`TS-TCC\u002Fdata\u002Fdataset_name`下创建相应的子目录，并将数据集放入其中。这由shell脚本`data_processing\u002FTS-TCC.sh`完成，它会创建文件夹和指向下载文件的软链接。\n\n对于TS2Vec，它使用的`{train,test}_{input,output}.npy`文件格式与Mixing-up完全相同，因此我们可以只对下载的数据集进行一次处理，并将其用于这两种模型。数据格式的唯一区别在于标签张量是二维的，因此我们需要为每个这样的张量插入一个新的维度。这一操作在`data_processing\u002FMixing-up.py`中完成，随后我们可以运行`data_processing\u002FTS2vec.sh`来为处理后的文件创建别名。\n\n接下来，对于CLOCS，我们需要构建一个更为复杂的嵌套字典，其中包含时间序列和标签。此外，由于CLOCS假设我们在数据预处理过程中已经丢弃了通道信息，因此时间序列样本现在以二维张量的形式存储，即去除了通道维度。同样，最终的数据集应放置在正确的位置，格式为`CLOCS\u002Fdata\u002Fdataset_name`。然而，由于别名问题，实际使用的名称可能与我们在论文中命名的数据集不一致。请使用Python脚本`data_processing\u002FCLOCS.py`自动完成上述步骤。\n\n最后，对于SimCLR，我们没有单独的数据文件夹，而是直接将文件放置在`SimCLR\u002Fdataset_name`目录下。关于数据本身，需要注意的是，存储时间序列的张量其第二和第三维（分别对应通道和观测值）与初始文件相比发生了互换。此外，标签不能是数值形式，而必须采用独热编码格式。这些操作都在`data_processing\u002FSimCLR.py`脚本中完成，以方便操作。\n\n当然，我们还提供了一个快捷脚本，只需在Git仓库的根目录下运行`process_all.sh`即可完成以上所有步骤。在运行这些脚本之前，请确保您处于`baseline_requirements.yml`中指定的正确环境中。\n\n## 实验设置\n\n我们在两种不同的设置下评估了我们的模型，并将其与八种基线方法进行了对比。这些基线包括六种可用于时间序列迁移学习的最先进模型，以及两种非预训练模型（一种非深度学习方法，此处为KNN；另一种是随机初始化的模型）。这两种不同的设置如下：\n\n**设置1：一对一预训练。** 我们在一个预训练数据集上对模型进行预训练，然后仅在单个目标数据集上进行微调。我们分别在四个独立场景中测试了所提出的模型：神经阶段检测、机械设备诊断、活动识别和身体状态监测。例如，在场景1（神经阶段检测）中，我们使用SleepEEG数据集进行预训练，然后在Epilepsy数据集上进行微调。尽管这两个数据集都描述的是单通道脑电图信号，但它们来自头皮上的不同通道\u002F位置，监测的是不同的生理过程（睡眠与癫痫），并且采集自不同的患者。这种设置模拟了实际应用中广泛存在的场景：当存在领域差距且微调数据集较小时，迁移学习可能非常有用。\n\n**设置2：一对多预训练。** 我们使用一个数据集进行预训练，随后在多个目标数据集上分别进行微调，而不从头开始重新预训练。我们选择SleepEEG作为预训练数据集，因为它数据量大且具有复杂的时序动态。然后我们在来自其他三个场景的Epilepsy、FD-B和EMG数据集上进行微调。这一次，预训练数据集与三个微调数据集之间的领域差距更大，因此该设置用于检验我们模型在迁移学习中的通用性。\n\n\u003C!-- **设置3：消融实验。** 为了评估预训练过程中模型各组件的相对重要性，我们修改或简化了损失函数并重复了实验。此外，我们还比较了部分微调与完全微调之间的性能差异。有关消融实验的更多详细信息，请参阅我们论文附录表7。 -->\n\n\n## 环境要求\n\nTF-C已在Python >=3.5环境下进行过测试。\n\n对于基线模型，由于原始实现差异较大，我们未能统一运行环境。因此，您需要搭建三个不同的环境来覆盖所有六个深度学习基线。对于ts2vec，请使用ts2vec_requirements.yml文件；对于SimCLR，由于Tang等人使用的是TensorFlow框架，因此请使用simclr_requirements.yml文件；对于其余四家基线，则使用`baseline_requirements.yml`文件。要通过Conda使用这些文件安装本项目所需的依赖项，请运行以下命令：\n\n`conda env create -f XXX_requirements.yml`\n\n## 代码运行\n\n**复现我们的TF-C** 请将处理好的数据集下载到`code\u002Fdata\u002FSleepEEG`文件夹中，并确保文件夹名称与数据集名称一致。有三个关键参数：*training_mode*有两个选项，分别为*pre_train*和*fine_tune_test*；*pretrain_dataset*有四个选项，分别是*SleepEEG*、*FD_A*、*HAR*和*ECG*；*target_dataset*也有四个选项，分别是*Epilepsy*、*FD_B*、*Gesture*和*EMG*。模型的超参数可在`config_files`文件夹中的配置文件中找到。例如，当您在SleepEEG数据集上预训练模型并在Epilepsy数据集上进行微调时，请运行：\n\n`python main.py --training_mode pre_train --pretrain_dataset SleepEEG --target_dataset Epilepsy`\n\n`python main.py --training_mode fine_tune_test --pretrain_dataset SleepEEG --target_dataset Epilepsy`\n\n**复现基线模型** 建议您尽可能按照各基线作者在其`README.md`文件中描述的命令行模式，从`code\u002Fbaselines\u002F`下的相应文件夹中运行模型。需要注意的是，在Mixing-up和SimCLR的情况下，预训练和微调是通过直接运行`train_model.py`和`finetune_model.py`完成的，无需传递参数。同样地，对于CLOCS，必须手动修改主文件（此处为`run_experiments.py`）中的超参数设置。如果您对这些基线模型的超参数设置有任何疑问，请联系其原作者。最后，对于每种基线，在不同的数据集组合上，迁移学习的效果会因超参数的选择而有所不同。我们已手动尝试了多种组合，并选择了在保持各基线模型复杂度相当的同时，能够获得最佳性能的参数配置。我们会在相应基线的文件夹中提供表格，详细列出针对不同数据集所使用的具体超参数组合，以便于复现我们的实验结果。请注意，某些基线是专为时间序列的表示学习设计的（而非预训练），我们将这些基线置于与我们的模型相同的实验设置中，以确保结果的可比性。\n\n## 引用\n\n如果您发现*TF-C*对您的研究有所帮助，请考虑引用本文：\n\n````\n```\n@inproceedings{zhang2022self,\ntitle = {Self-Supervised Contrastive Pre-Training For Time Series via Time-Frequency Consistency},\nauthor = {Zhang, Xiang and Zhao, Ziyuan and Tsiligkaridis, Theodoros and Zitnik, Marinka},\nbooktitle = {Proceedings of Neural Information Processing Systems, NeurIPS},\nyear      = {2022}\n}\n```\n````\n\n## 更新于2023年1月\n\n我们在以下几个方面对所提出的TF-C模型的实现进行了更新：\n\n1. 修复了错误、清理了代码，并添加了注释以提高可读性。新上传的TF-C代码位于路径 `TFC-pretraining\u002Fcode\u002FTFC` 下。该文件夹中提供了运行所需的所有必要文件。\n2. 对于时域和频域中的对比编码器，我们将原有的三层卷积神经网络块替换为两层Transformer。我们发现，虽然性能并未提升（甚至略有下降），但模型的稳定性有所改善。\n3. 在下游分类器部分，我们在原有的两层MLP分类器之外，新增了一个KNN分类器。初步实验表明，MLP的性能会因不同的设置和超参数而波动。因此，在本版本中，我们同时提供了两种分类器：两层MLP和KNN（K=5）。然而，导致性能波动的具体原因仍不明确，有待进一步研究。\n4. 为了便于复现，我们在此提供一个预训练模型的示例。模型权重位于路径 `TFC-pretraining\u002Fcode\u002Fexperiments_logs\u002FSleepEEG_2_Epilepsy\u002Frun1\u002Fpre_train_seed_42_2layertransformer\u002Fsaved_models\u002Fckp_last.pt`。该模型路径与代码中使用的路径一致，因此您可以直接克隆或下载整个仓库，并运行 `TFC-pretraining\u002Fcode\u002FTFC\u002Fmain.py` 文件。\n    - 该模型是在“SleepEEG到Epilepsy”场景下预训练的（本次更新的所有调试均基于此设置）。具体而言，将训练模式设置为 `pre_train`，预训练数据集设置为 `SleepEEG`。在 `SleepEEG_Configs.py` 中，所有超参数均未更改，即学习率lr=0.0005，预训练轮数为200（而微调轮数为20）。随机种子设置为42。\n    - 在Epilepsy数据集上的微调阶段（学习率lr=0.0005，轮数20，批次大小60），微调集仍为60个样本（30个阳性+30个阴性）。验证集包含20个样本，测试集则有11420个样本。不过，为了测试模型的稳定性，我们重新划分了Epilepsy数据集（即重新生成了60个微调样本）。重新划分的代码位于 `TFC-pretraining\u002Fcode\u002FTFC\u002FData_split.py`，划分后的数据集已上传至本仓库的 `TFC-pretraining\u002Fdatasets\u002FEpilepsy\u002F` 目录下，并同步至Figshare。\n    - 在上述设置下，借助TF-C框架，微调集上的最佳测试性能为F1约0.88（由MLP实现，优于KNN）；而在未进行TF-C预训练的情况下，该指标仅为约0.60。*请注意，为便于快速调试，该模型是在SleepEEG数据集的一个子集上预训练的（仅1280个样本，占整个数据集不到1%）。因此，我们认为，若使用更多预训练样本，模型性能仍有较大提升空间。*\n5. 我们希望在后续工作中分享更多可能改进TF-C框架的想法：\n    - 可根据具体任务调整两层Transformer的结构（例如，针对复杂的时间序列增加层数）。对主干网络的优化可能会有所帮助。另外，切换到Transformer后，我们并未对超参数进行调优，采用更优的超参数组合（如层数、Transformer的维度、MLP隐藏层的维度等）可能会带来更好的效果。\n    - 在基于时间的编码器和基于频率的编码器中使用不同的架构。由于信号在频域和时域中的特性差异较大，采用专门的编码器架构有助于更好地捕捉信息。\n    - 探索更多频域增强方法。目前我们主要通过添加或移除频率成分来进行增强，未来可以尝试设计更多扰动方式（如带通滤波）。\n    - 在频域中，我们仅利用了幅度信息，而相位同样非常重要。因此，未来的重要研究方向是充分挖掘频域中的信息。\n    - 改进投影机制。目前我们将时域和频域的嵌入投影到一个共享的时频域中，所使用的投影器结构为两层MLP，较为简单。欢迎探索更强大、更有帮助的投影方法。\n    - 还有许多其他想法有待补充。\n\n## 其他说明\n\n如果您对代码和\u002F或算法有任何疑问，请发送邮件至 \u003Cxiang.alan.zhang@gmail.com>。\n\n\n\n## 许可证\n\nTF-C代码库采用MIT许可证发布。","# TFC-pretraining 快速上手指南\n\nTFC (Time-Frequency Consistency) 是一种针对时间序列数据的自监督对比预训练方法。它通过拉近同一时间序列样本在“时域”和“频域”的嵌入表示，学习可迁移的通用特征，适用于睡眠分析、癫痫检测、故障诊断等多种场景。\n\n## 环境准备\n\n在开始之前，请确保您的开发环境满足以下要求：\n\n*   **操作系统**: Linux (推荐 Ubuntu 18.04+) 或 macOS\n*   **Python 版本**: Python 3.7 - 3.9\n*   **硬件要求**: 建议使用支持 CUDA 的 NVIDIA GPU 进行加速（预训练过程计算量较大）\n*   **前置依赖**:\n    *   PyTorch (>= 1.8.0)\n    *   NumPy\n    *   SciPy\n    *   Scikit-learn\n    *   Pandas\n\n## 安装步骤\n\n### 1. 克隆项目代码\n首先从 GitHub 克隆仓库到本地：\n\n```bash\ngit clone https:\u002F\u002Fgithub.com\u002Fmims-harvard\u002FRaindrop.git\ncd Raindrop\n# 注意：根据 README 描述，TF-C 代码位于此仓库中，请确认具体子目录或文件结构\n```\n\n*(注：如果该项目有独立的 TF-C 专用仓库，请替换为对应的 `git clone` 地址。根据提供的 README，作者关联了 `mims-harvard\u002FRaindrop`，但具体 TF-C 代码通常在名为 `TF-C` 的独立仓库或该仓库的特定分支中。若存在独立仓库 `xiangzhang\u002FTF-C`，请使用：`git clone https:\u002F\u002Fgithub.com\u002Fxiangzhang\u002FTF-C.git`)*\n\n假设使用标准 Python 包管理，安装依赖：\n\n```bash\npip install torch torchvision torchaudio --index-url https:\u002F\u002Fdownload.pytorch.org\u002Fwhl\u002Fcu118\npip install numpy scipy scikit-learn pandas matplotlib\n```\n\n> **国内加速提示**：如果您在中国大陆，建议使用清华或阿里镜像源加速 PyTorch 和其他包的安装：\n> ```bash\n> pip install torch torchvision torchaudio --index-url https:\u002F\u002Fmirrors.tuna.tsinghua.edu.cn\u002Fpypi\u002Fweb\u002Fsimple\n> pip install -r requirements.txt -i https:\u002F\u002Fmirrors.aliyun.com\u002Fpypi\u002Fsimple\u002F\n> ```\n\n### 2. 数据准备\n本项目包含 8 个处理好的数据集（SleepEEG, Epilepsy, FD-A\u002FB, HAR, Gesture, ECG, EMG）。\n*   **自动下载**：检查项目中是否包含数据下载脚本（通常位于 `data\u002F` 或 `scripts\u002F` 目录下），运行即可自动获取预处理后的数据。\n*   **手动放置**：如果需手动下载原始数据，请参考 README 中的链接下载，并按照项目要求的格式放入 `data\u002F` 目录。\n\n## 基本使用\n\n以下是基于命令行运行 TF-C 预训练及微调的最简流程。\n\n### 1. 运行预训练 (Pre-training)\n在无标签的大规模数据集上进行自监督预训练，学习时频一致性特征。\n\n```bash\npython main.py --mode pretrain \\\n               --dataset SleepEEG \\\n               --gpu_id 0 \\\n               --batch_size 256 \\\n               --epochs 100\n```\n\n*   `--mode`: 设置为 `pretrain`。\n*   `--dataset`: 选择预训练数据集（如 `SleepEEG`, `HAR` 等）。\n*   模型权重将默认保存在 `checkpoints\u002F` 目录。\n\n### 2. 运行微调 (Fine-tuning)\n使用预训练好的模型，在小规模标注数据集上进行微调以执行分类任务。\n\n```bash\npython main.py --mode finetune \\\n               --pretrained_path checkpoints\u002Ftfc_pretrain_sleep.pth \\\n               --dataset Epilepsy \\\n               --gpu_id 0 \\\n               --batch_size 64 \\\n               --epochs 50\n```\n\n*   `--mode`: 设置为 `finetune`。\n*   `--pretrained_path`: 指向第一步生成的预训练模型权重文件。\n*   `--dataset`: 指定下游任务数据集（如 `Epilepsy`, `FD-A` 等）。\n\n### 3. 评估结果\n微调完成后，脚本会自动在测试集上评估模型性能，输出准确率 (Accuracy)、F1 分数等指标。\n\n```text\nTest Accuracy: 0.9234\nMacro F1 Score: 0.9105\n```\n\n---\n**提示**：具体的超参数（如学习率、编码器层数等）可根据不同数据集的特性在 `config.py` 或通过命令行参数进行调整，详见项目源码注释。","某工业预测性维护团队正试图利用振动传感器数据，提前识别旋转机械的潜在故障，但面临标注数据稀缺且工况多变的挑战。\n\n### 没有 TFC-pretraining 时\n- **标注依赖严重**：传统监督学习需要大量人工标记的故障样本，而实际生产中故障罕见，导致模型因训练数据不足而无法收敛。\n- **泛化能力薄弱**：在不同转速或负载下采集的数据分布差异巨大，在一个工况训练的模型换到另一台设备上准确率断崖式下跌。\n- **特征提取片面**：单独使用时域或频域分析容易丢失关键信息，难以捕捉振动信号中时间动态与频率成分之间的内在一致性关联。\n- **冷启动成本高**：每接入新类型的传感器或新场景，都需要重新收集数据并从头训练模型，部署周期长达数周。\n\n### 使用 TFC-pretraining 后\n- **实现无监督预训练**：利用海量未标注的原始振动数据，通过时频一致性对比学习预先提取通用特征，大幅降低对故障标签的依赖。\n- **跨域迁移能力强**：模型学到了时间序列底层的共性模式，只需少量目标场景数据进行微调，即可适应不同设备或变工况下的故障检测。\n- **表征更加鲁棒**：强制时域嵌入与频域嵌入在潜在空间靠近，使模型能同时捕捉瞬态冲击与频谱规律，显著提升了复杂噪声下的识别精度。\n- **快速落地新场景**：基于预训练权重进行微调，将新产线的模型开发周期从数周缩短至几天，实现了高效的“预训练 + 微调”工作流。\n\nTFC-pretraining 通过挖掘时间序列独有的时频一致性，成功解决了工业场景下小样本、多变量导致的模型泛化难题，让预测性维护真正具备规模化落地能力。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fmims-harvard_TFC-pretraining_f123e4a0.png","mims-harvard","Artificial Intelligence for Medicine and Science @ Harvard Zitnik Lab","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Fmims-harvard_5a3b6165.png","",null,"marinka@hms.harvard.edu","marinkazitnik","https:\u002F\u002Fzitniklab.hms.harvard.edu","https:\u002F\u002Fgithub.com\u002Fmims-harvard",[82,86],{"name":83,"color":84,"percentage":85},"Python","#3572A5",99.2,{"name":87,"color":88,"percentage":89},"Shell","#89e051",0.8,520,94,"2026-04-04T14:07:37","MIT","未说明",{"notes":96,"python":94,"dependencies":97},"提供的 README 内容主要介绍了 TF-C 模型的原理、应用场景及数据集详情，未包含具体的运行环境需求（如操作系统、GPU\u002F内存配置、Python 版本或依赖库列表）。建议查阅项目仓库中的 requirements.txt、setup.py 文件或完整论文以获取安装指南。",[],[14],[100,101,102,103,104,105,106],"consistency-models","contrastive-learning","deep-learning","pre-trained-model","representation-learning","self-supervised-learning","time-series","2026-03-27T02:49:30.150509","2026-04-09T05:24:01.918033",[110,115,120,125,130,134],{"id":111,"question_zh":112,"answer_zh":113,"source_url":114},25660,"在 SleepEEG -> Epilepsy 迁移任务中，预训练和微调的具体超参数（如轮数、批次大小）是多少？","根据维护者回复：\n1. **预训练 (Pre-training)**: 在 SleepEEG 数据上，批次大小 (batch size) 设为 128，运行 200 个 epoch。虽然也尝试过 40、100、300 个 epoch，但发现 200 个 epoch 效果最好。\n2. **微调 (Fine-tuning)**: 针对只有 60 个样本的目标数据，配置文件中的批次大小设为 60。在这种设置下，一个 epoch 等同于一个 batch（因为样本数 60 小于默认批次上限 64）。\n注意：代码库已在 2023 年 1 月更新，修复了相关 bug 并清理了代码，建议使用最新版本。","https:\u002F\u002Fgithub.com\u002Fmims-harvard\u002FTFC-pretraining\u002Fissues\u002F2",{"id":116,"question_zh":117,"answer_zh":118,"source_url":119},25661,"为什么我无法复现论文中的结果，或者复现的准确率远低于预期？","结果差异可能由以下原因导致：\n1. **数据量配置**: 仓库中共享的模型参数（2023 年 1 月更新版）仅使用了 1% 的数据样本进行训练，旨在方便快速调试和测试。为了获得更好的性能和稳定性，建议在完整数据集上进行训练。\n2. **环境差异**: 结果波动可能源于参数初始化、硬件差异（GPU\u002FCPU）或库版本（如 cuDNN）不同导致的浮点运算细微差别。\n3. **代码版本**: 早期版本存在混乱和 bug，请务必使用 2023 年 1 月更新后的清理版本，该版本将对比编码器的 3 层 CNN 块替换为 2 层 Transformer，并增加了 KNN 分类器。","https:\u002F\u002Fgithub.com\u002Fmims-harvard\u002FTFC-pretraining\u002Fissues\u002F30",{"id":121,"question_zh":122,"answer_zh":123,"source_url":124},25662,"运行 FDA 数据集或其他一对一场景时出现预处理错误，提示 'sample' 是数组而非张量，如何解决？","该错误是因为数据加载时 'sample' 是 numpy 数组而不是 tensor。解决方法如下：\n需要手动加载数据，将 'sample' 显式转换为 tensor 格式，然后重新保存。完成此步骤后，程序即可正常运行。这通常发生在除 FD_A2FD_B 以外的其他一对一场景中。","https:\u002F\u002Fgithub.com\u002Fmims-harvard\u002FTFC-pretraining\u002Fissues\u002F16",{"id":126,"question_zh":127,"answer_zh":128,"source_url":129},25663,"DataTransform 函数中存在索引类型错误和逻辑错误（只有前两个样本被增强），如何修复？","这是旧版本代码的已知 Bug，已在 2023 年 1 月的更新中修复。具体问题及修复方案：\n1. **索引类型错误**: `1-li_onehot[:, num]` 生成的是浮点型数组，不能作为索引。需确保索引为整数类型。\n2. **逻辑错误**: 原代码逻辑导致只有前两个样本有机会被置零，大部分样本未被处理。\n3. **频率域增强**: `DataTransform_FD` 中的某些行被意外取消注释，实际上应该注释掉。频率增强应通过专门的函数（如 `remove_frequency`）实现，而不是通过错误的索引操作。\n建议直接拉取最新的代码版本，维护者已确认新版本修复了这些 bug 并添加了注释。","https:\u002F\u002Fgithub.com\u002Fmims-harvard\u002FTFC-pretraining\u002Fissues\u002F9",{"id":131,"question_zh":132,"answer_zh":133,"source_url":114},25664,"2023 年 1 月的代码更新主要包含哪些改进和新特性？","2023 年 1 月的更新主要包含以下内容：\n1. **代码清理**: 修复了已知 bug，清理了代码结构，并添加了注释以提高可读性。\n2. **架构升级**: 对于时域和频域的对比编码器，将原来的 3 层 CNN 块替换为 2 层 Transformer 结构。\n3. **分类器增强**: 在下流任务分类器中，除了原有的 2 层 MLP 分类器外，并行增加了一个 KNN 分类器。\n4. **未来方向**: 分享了更多可能改进 TF-C 框架的思路供后续工作参考。",{"id":135,"question_zh":136,"answer_zh":137,"source_url":124},25665,"ECG2EMG 微调模式下性能停滞且只有论文报告的一半，是什么原因？","这种情况通常是由代码版本过旧或未正确修复数据预处理 Bug 导致的。用户反馈显示，在使用旧代码时，性能在所有 epoch 中保持不变且数值偏低。请执行以下操作：\n1. 确保使用的是 2023 年 1 月更新后的最新代码版本。\n2. 检查是否已按照 Issue #16 的建议，手动将数据集中的 'sample' 从数组转换为 tensor 并重新保存。\n3. 确认数据增强模块（DataTransform）是否已应用了最新的修复补丁，避免只有少量样本被增强的情况。",[]]