File size: 2,081 Bytes
d5dac94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bb9bb65
d5dac94
 
 
bb9bb65
d5dac94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
364a6fb
d5dac94
bb9bb65
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"""ttv_utils包提供了用于特征预测 和 模型训练过程收集 的工具函数

主要组件:
1. FeaturePredictor: 用于从模型中间层特征向量预测预测结果的类
   使用示例:
   ```python
           predictor = FeaturePredictor(
            model_class=model, 模型类
            model_weights_path=weight_path,模型权重文件路径
            layer_info_path=layer_info_path,层信息文件路径
            device=device 运行设备
        )
   ```

2. predict_feature: 从模型中间层特征向量预测预测结果便捷函数
   使用示例:
   ```python
       output = predict_feature(
           model=model,             # 模型类
           weight_path=weight_path, # 模型权重文件路径
           layer_info_path=layer_info_path, # 层信息文件路径
           feature=feature,         # 特征向量
           device=device             # 运行设备
       )
   ```

3. time_travel_saver: 用于在训练过程中保存模型权重、特征和预测结果的类
   使用示例:
   ```python
   # 创建一个保存器实例
   saver = time_travel_saver(
       model=model,                    # 模型实例
       dataloader=ordered_loader,      # 顺序数据加载器
       device='cuda:0',                # 计算设备
       save_dir='./checkpoints',       # 保存根目录
       model_name='alexnet',           # 模型名称
       interval=1                      # 每隔多少个epoch保存一次
   )
   
   # 在训练循环中调用save方法
   for epoch in range(epochs):
       # 训练代码...
       if epoch % interval == 0:
            saver.save(model)  # 保存当前epoch的模型状态
   ```

   保存的文件结构:
   - model/{epoch}.pth: 模型权重
   - dataset/representation/{epoch}.npy: 特征向量
   - dataset/prediction/{epoch}.npy: 预测结果
   - dataset/label/labels.npy: 标签
"""

from .feature_predictor import FeaturePredictor, predict_feature
from .save_embeddings import time_travel_saver

__all__ = ['FeaturePredictor', 'predict_feature', 'time_travel_saver']