README.md 2.8 KB
Newer Older
H
hypox64 已提交
1 2 3
<div align="center">    
<img src="./imgs/compare.png " alt="image" style="zoom:100%;" />
</div>
H
hypox64 已提交
4

H
Hypo 已提交
5
# candock
H
hypox64 已提交
6

H
hypox64 已提交
7
| English | [中文版](./README_CN.md) |<br><br>
H
hypox64 已提交
8 9
A time series signal analysis and classification framework.<br>
It contain multiple network  and provide data preprocessing, reading, training, evaluation, testing and other functions.<br>
H
hypox64 已提交
10 11
Some output examples: [heatmap](./image/heatmap_eg.png)  [running_loss](./image/running_loss_eg.png)  [log.txt](./docs/log_eg.txt)<br>
Supported network:<br>
H
hypox64 已提交
12

H
hypox64 已提交
13 14 15
>1d
>
>>lstm, cnn_1d, resnet18_1d, resnet34_1d, multi_scale_resnet_1d, micro_multi_scale_resnet_1d
H
hypox64 已提交
16

H
hypox64 已提交
17 18 19 20 21 22 23 24

>2d(stft spectrum)
>
>>mobilenet, resnet18, resnet50, resnet101, densenet121, densenet201, squeezenet, dfcnn, multi_scale_resnet,

## A example: Use EEG to classify sleep stage
[sleep-edfx](https://github.com/HypoX64/candock/tree/f24cc44933f494d2235b3bf965a04cde5e6a1ae9)<br>
Thank [@swalltail99](https://github.com/swalltail99)for the bug. In other to load sleep-edfx dataset,please install mne==0.18.0<br>
H
hypox64 已提交
25 26 27
```bash
pip install mne==0.18.0
```
H
hypox64 已提交
28 29 30 31 32 33 34
## Getting Started
### Prerequisites
- Linux, Windows,mac
- CPU or NVIDIA GPU + CUDA CuDNN
- Python 3
- Pytroch 1.0+
### Dependencies
H
hypox64 已提交
35
This code depends on torchvision, numpy, scipy , matplotlib, available via pip install.<br>
H
hypox64 已提交
36 37 38 39
For example:<br>

```bash
pip3 install matplotlib
H
hypox64 已提交
40
```
H
hypox64 已提交
41 42 43 44
### Clone this repo:
```bash
git clone https://github.com/HypoX64/candock
cd candock
H
hypox64 已提交
45
```
H
hypox64 已提交
46 47 48 49 50 51 52 53 54
### Download dataset and pretrained-model
[[Google Drive]](https://drive.google.com/open?id=1NTtLmT02jqlc81lhtzQ7GlPK8epuHfU5)   [[百度云,y4ks]](https://pan.baidu.com/s/1WKWZL91SekrSlhOoEC1bQA)

* This datasets consists of signals.npy(shape:18207, 1, 2000) and labels.npy(shape:18207) which can be loaded by "np.load()".
* samples:18207,  channel:1,  length of each sample:2000,  class:50
* Top1 err: 2.09%
### Train
```bash
python3 train.py --label 50 --input_nc 1 --dataset_dir ./datasets/simple_test --save_dir ./checkpoints/simple_test --model_name micro_multi_scale_resnet_1d --gpu_id 0 --batchsize 64 --k_fold 5
H
hypox64 已提交
55
# if you want to use cpu to train, please input --gpu_id -1
H
hypox64 已提交
56
```
H
hypox64 已提交
57
* More [options](./util/options.py).
H
hypox64 已提交
58 59 60 61 62 63 64
### Test
```bash
python3 simple_test.py --label 50 --input_nc 1 --model_name micro_multi_scale_resnet_1d --gpu_id 0
# if you want to use cpu to test, please input --gpu_id -1
```

## Training with your own dataset
H
hypox64 已提交
65 66 67 68
* step1: Generate signals.npy and labels.npy in the following format.
```python
#1.type:numpydata   signals:np.float64   labels:np.int64
#2.shape  signals:[num,ch,length]    labels:[num]
H
hypox64 已提交
69
#num:samples_num, ch :channel_num,  length:length of each sample
H
hypox64 已提交
70 71 72 73
#for example:
signals = np.zeros((10,1,10),dtype='np.float64')
labels = np.array([0,0,0,0,0,1,1,1,1,1])      #0->class0    1->class1
```
H
hypox64 已提交
74
* step2: input  ```--dataset_dir "your_dataset_dir"``` when running code.
H
hypox64 已提交
75