OpenSpliceai 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- OpenSpliceai-0.0.1.dist-info/LICENSE +674 -0
- OpenSpliceai-0.0.1.dist-info/METADATA +177 -0
- OpenSpliceai-0.0.1.dist-info/RECORD +42 -0
- OpenSpliceai-0.0.1.dist-info/WHEEL +5 -0
- OpenSpliceai-0.0.1.dist-info/entry_points.txt +2 -0
- OpenSpliceai-0.0.1.dist-info/top_level.txt +1 -0
- openspliceai/__init__.py +1 -0
- openspliceai/calibrate/__init__.py +0 -0
- openspliceai/calibrate/calibrate.py +85 -0
- openspliceai/calibrate/calibrate_utils.py +42 -0
- openspliceai/calibrate/model_utils.py +59 -0
- openspliceai/calibrate/temperature_scaling.py +211 -0
- openspliceai/calibrate/visualization.py +99 -0
- openspliceai/constants.py +14 -0
- openspliceai/create_data/__init__.py +0 -0
- openspliceai/create_data/create_datafile.py +159 -0
- openspliceai/create_data/create_dataset.py +64 -0
- openspliceai/create_data/paralogs.py +81 -0
- openspliceai/create_data/utils.py +254 -0
- openspliceai/create_data/verify_h5_file.py +61 -0
- openspliceai/header.py +11 -0
- openspliceai/merge_data/__init__.py +0 -0
- openspliceai/merge_data/merge_dataset.py +103 -0
- openspliceai/openspliceai.py +197 -0
- openspliceai/predict/__init__.py +0 -0
- openspliceai/predict/predict.py +1091 -0
- openspliceai/predict/utils.py +53 -0
- openspliceai/test/__init__.py +0 -0
- openspliceai/test/spliceai.py +45 -0
- openspliceai/test/test.py +92 -0
- openspliceai/train/__init__.py +0 -0
- openspliceai/train/train.py +76 -0
- openspliceai/train_base/__init__.py +0 -0
- openspliceai/train_base/spliceai.py +61 -0
- openspliceai/train_base/utils.py +644 -0
- openspliceai/transfer/__init__.py +0 -0
- openspliceai/transfer/transfer.py +107 -0
- openspliceai/variant/__init__.py +0 -0
- openspliceai/variant/get_anno.py +129 -0
- openspliceai/variant/test.py +31 -0
- openspliceai/variant/utils.py +541 -0
- openspliceai/variant/variant.py +89 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
###############################################################################
|
|
2
|
+
'''This code has functions which process the information in the .h5 files
|
|
3
|
+
datafile_{}_{}.h5 and convert them into a format usable by Keras.'''
|
|
4
|
+
###############################################################################
|
|
5
|
+
|
|
6
|
+
# PROCESSING BATCH SIZE
|
|
7
|
+
from math import ceil
|
|
8
|
+
def ceil_div(x, y):
|
|
9
|
+
"""
|
|
10
|
+
Calculate the ceiling of a division between two numbers.
|
|
11
|
+
|
|
12
|
+
Parameters:
|
|
13
|
+
- x (int): Numerator
|
|
14
|
+
- y (int): Denominator
|
|
15
|
+
|
|
16
|
+
Returns:
|
|
17
|
+
- int: The ceiling of the division result.
|
|
18
|
+
"""
|
|
19
|
+
return int(ceil(float(x)/y))
|
|
20
|
+
|
|
21
|
+
# FOR TESTING PURPOSES
|
|
22
|
+
import os, sys
|
|
23
|
+
import psutil
|
|
24
|
+
def log_memory_usage():
|
|
25
|
+
process = psutil.Process(os.getpid())
|
|
26
|
+
print(f"Memory usage: {process.memory_info().rss / (1024 * 1024)} MB", file=sys.stderr)
|
|
27
|
+
|
|
28
|
+
# SETUP INITIALIZATION
|
|
29
|
+
def initialize_constants(flanking_size, hdf_threshold_len=0, flush_predict_threshold=500, chunk_size=100, split_fasta_threshold=1500000):
|
|
30
|
+
from openspliceai.constants import SL
|
|
31
|
+
|
|
32
|
+
assert int(flanking_size) in [80, 400, 2000, 10000]
|
|
33
|
+
|
|
34
|
+
CL_max = flanking_size # context length for sequence prediction (flanking size sum)
|
|
35
|
+
HDF_THRESHOLD_LEN = hdf_threshold_len # maximum size before reading sequence into an HDF file for storage
|
|
36
|
+
FLUSH_PREDICT_THRESHOLD = flush_predict_threshold # maximum number of predictions before flushing to file
|
|
37
|
+
CHUNK_SIZE = chunk_size # chunk size for loading hdf5 dataset
|
|
38
|
+
SPLIT_FASTA_THRESHOLD = split_fasta_threshold # maximum length of fasta entry before splitting
|
|
39
|
+
|
|
40
|
+
return {'SL': SL,
|
|
41
|
+
'CL_max': CL_max,
|
|
42
|
+
'HDF_THRESHOLD_LEN': HDF_THRESHOLD_LEN,
|
|
43
|
+
'FLUSH_PREDICT_THRESHOLD': FLUSH_PREDICT_THRESHOLD,
|
|
44
|
+
'CHUNK_SIZE': CHUNK_SIZE,
|
|
45
|
+
'SPLIT_FASTA_THRESHOLD': SPLIT_FASTA_THRESHOLD}
|
|
46
|
+
|
|
47
|
+
def initialize_paths(output_dir, flanking_size, sequence_length, model_arch='SpliceAI'):
|
|
48
|
+
"""Initialize project directories and create them if they don't exist."""
|
|
49
|
+
BASENAME = f"{model_arch}_{sequence_length}_{flanking_size}"
|
|
50
|
+
model_pred_outdir = f"{output_dir}/{BASENAME}/"
|
|
51
|
+
os.makedirs(model_pred_outdir, exist_ok=True)
|
|
52
|
+
|
|
53
|
+
return model_pred_outdir
|
|
File without changes
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import torch
|
|
2
|
+
import torch.nn as nn
|
|
3
|
+
import torch.nn.functional as F
|
|
4
|
+
import numpy as np
|
|
5
|
+
|
|
6
|
+
class ResidualUnit(nn.Module):
|
|
7
|
+
def __init__(self, l, w, ar):
|
|
8
|
+
super().__init__()
|
|
9
|
+
self.batchnorm1 = nn.BatchNorm1d(l)
|
|
10
|
+
self.batchnorm2 = nn.BatchNorm1d(l)
|
|
11
|
+
self.relu1 = nn.LeakyReLU(0.1)
|
|
12
|
+
self.relu2 = nn.LeakyReLU(0.1)
|
|
13
|
+
self.conv1 = nn.Conv1d(l, l, w, dilation=ar, padding=(w-1)*ar//2)
|
|
14
|
+
self.conv2 = nn.Conv1d(l, l, w, dilation=ar, padding=(w-1)*ar//2)
|
|
15
|
+
|
|
16
|
+
def forward(self, x):
|
|
17
|
+
residual = x
|
|
18
|
+
out = self.conv1(self.relu1(self.batchnorm1(x)))
|
|
19
|
+
out = self.conv2(self.relu2(self.batchnorm2(out)))
|
|
20
|
+
return residual + out
|
|
21
|
+
|
|
22
|
+
class Cropping1D(nn.Module):
|
|
23
|
+
def __init__(self, cropping):
|
|
24
|
+
super().__init__()
|
|
25
|
+
self.cropping = cropping
|
|
26
|
+
|
|
27
|
+
def forward(self, x):
|
|
28
|
+
return x[:, :, self.cropping[0]:-self.cropping[1]] if self.cropping[1] > 0 else x[:, :, self.cropping[0]:]
|
|
29
|
+
|
|
30
|
+
class SpliceAI(nn.Module):
|
|
31
|
+
def __init__(self, L, W, AR):
|
|
32
|
+
super(SpliceAI, self).__init__()
|
|
33
|
+
self.initial_conv = nn.Conv1d(4, L, 1)
|
|
34
|
+
self.residual_units = nn.ModuleList([ResidualUnit(L, W[i], AR[i]) for i in range(len(W))])
|
|
35
|
+
self.final_conv = nn.Conv1d(L, 3, 1)
|
|
36
|
+
self.CL = 2 * np.sum(AR * (W - 1))
|
|
37
|
+
self.crop = Cropping1D((self.CL//2, self.CL//2)) # Adjust this based on your specific needs
|
|
38
|
+
|
|
39
|
+
def forward(self, x):
|
|
40
|
+
x = self.initial_conv(x)
|
|
41
|
+
for ru in self.residual_units:
|
|
42
|
+
x = ru(x)
|
|
43
|
+
x = self.crop(x) # Apply cropping here
|
|
44
|
+
out = self.final_conv(x)
|
|
45
|
+
return F.softmax(out, dim=1) # Consider returning logits during training
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
from openspliceai.train_base.spliceai import *
|
|
2
|
+
from openspliceai.train_base.utils import *
|
|
3
|
+
from keras.models import load_model
|
|
4
|
+
|
|
5
|
+
def initialize_model_and_optim(device, flanking_size, pretrained_model, random_seed, test_target):
|
|
6
|
+
L = 32
|
|
7
|
+
N_GPUS = 2
|
|
8
|
+
W = np.asarray([11, 11, 11, 11])
|
|
9
|
+
AR = np.asarray([1, 1, 1, 1])
|
|
10
|
+
BATCH_SIZE = 18 * N_GPUS
|
|
11
|
+
if int(flanking_size) == 80:
|
|
12
|
+
W = np.asarray([11, 11, 11, 11])
|
|
13
|
+
AR = np.asarray([1, 1, 1, 1])
|
|
14
|
+
BATCH_SIZE = 18 * N_GPUS
|
|
15
|
+
elif int(flanking_size) == 400:
|
|
16
|
+
W = np.asarray([11, 11, 11, 11, 11, 11, 11, 11])
|
|
17
|
+
AR = np.asarray([1, 1, 1, 1, 4, 4, 4, 4])
|
|
18
|
+
BATCH_SIZE = 18 * N_GPUS
|
|
19
|
+
elif int(flanking_size) == 2000:
|
|
20
|
+
W = np.asarray([11, 11, 11, 11, 11, 11, 11, 11,
|
|
21
|
+
21, 21, 21, 21])
|
|
22
|
+
AR = np.asarray([1, 1, 1, 1, 4, 4, 4, 4,
|
|
23
|
+
10, 10, 10, 10])
|
|
24
|
+
BATCH_SIZE = 12 * N_GPUS
|
|
25
|
+
elif int(flanking_size) == 10000:
|
|
26
|
+
W = np.asarray([11, 11, 11, 11, 11, 11, 11, 11,
|
|
27
|
+
21, 21, 21, 21, 41, 41, 41, 41])
|
|
28
|
+
AR = np.asarray([1, 1, 1, 1, 4, 4, 4, 4,
|
|
29
|
+
10, 10, 10, 10, 25, 25, 25, 25])
|
|
30
|
+
BATCH_SIZE = 6 * N_GPUS
|
|
31
|
+
CL = 2 * np.sum(AR * (W - 1))
|
|
32
|
+
print("\033[1mContext nucleotides: %d\033[0m" % (CL))
|
|
33
|
+
print("\033[1mSequence length (output): %d\033[0m" % (SL))
|
|
34
|
+
if test_target == "SpliceAI-Keras":
|
|
35
|
+
model = load_model(pretrained_model)
|
|
36
|
+
params = {'L': L, 'W': W, 'AR': AR, 'CL': CL, 'SL': SL, 'BATCH_SIZE': BATCH_SIZE, 'RANDOM_SEED': random_seed}
|
|
37
|
+
return model, params
|
|
38
|
+
elif test_target == "OpenSpliceAI":
|
|
39
|
+
# Initialize the model
|
|
40
|
+
model = SpliceAI(L, W, AR).to(device)
|
|
41
|
+
# Print the shapes of the parameters in the initialized model
|
|
42
|
+
print("\nInitialized model parameter shapes:")
|
|
43
|
+
for name, param in model.named_parameters():
|
|
44
|
+
print(f"{name}: {param.shape}", end=", ")
|
|
45
|
+
|
|
46
|
+
# Load the pretrained model
|
|
47
|
+
state_dict = torch.load(pretrained_model, map_location=device)
|
|
48
|
+
|
|
49
|
+
# Filter out unnecessary keys and load matching keys into model
|
|
50
|
+
model_dict = model.state_dict()
|
|
51
|
+
state_dict = {k: v for k, v in state_dict.items() if k in model_dict and v.size() == model_dict[k].size()}
|
|
52
|
+
|
|
53
|
+
# Load state dict into the model
|
|
54
|
+
missing_keys, unexpected_keys = model.load_state_dict(state_dict, strict=False)
|
|
55
|
+
|
|
56
|
+
# Print missing and unexpected keys
|
|
57
|
+
print("\nMissing keys:", missing_keys)
|
|
58
|
+
print("Unexpected keys:", unexpected_keys)
|
|
59
|
+
|
|
60
|
+
# Set up optimizer and scheduler
|
|
61
|
+
optimizer = optim.AdamW(filter(lambda p: p.requires_grad, model.parameters()), lr=1e-4)
|
|
62
|
+
scheduler = optim.lr_scheduler.ReduceLROnPlateau(optimizer, mode='min', factor=0.5, patience=2, verbose=True)
|
|
63
|
+
print(model, file=sys.stderr)
|
|
64
|
+
params = {'L': L, 'W': W, 'AR': AR, 'CL': CL, 'SL': SL, 'BATCH_SIZE': BATCH_SIZE, 'N_GPUS': N_GPUS, 'RANDOM_SEED': random_seed}
|
|
65
|
+
return model, optimizer, scheduler, params
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def test(args):
|
|
69
|
+
print("Running OpenSpliceAI with 'test' mode")
|
|
70
|
+
if args.test_target == "OpenSpliceAI":
|
|
71
|
+
device = setup_environment(args)
|
|
72
|
+
log_output_test_base = initialize_test_paths(args)
|
|
73
|
+
test_h5f = load_test_datasets(args)
|
|
74
|
+
test_idxs = generate_test_indices(args.random_seed, test_h5f)
|
|
75
|
+
model, optimizer, scheduler, params = initialize_model_and_optim(device, args.flanking_size, args.pretrained_model, args.random_seed, args.test_target)
|
|
76
|
+
test_metric_files = create_metric_files(log_output_test_base)
|
|
77
|
+
test_model(model, optimizer, test_h5f, test_idxs, args, device, params, test_metric_files)
|
|
78
|
+
test_h5f.close()
|
|
79
|
+
elif args.test_target == "SpliceAI-Keras":
|
|
80
|
+
device = setup_environment(args)
|
|
81
|
+
log_output_test_base = initialize_test_paths(args)
|
|
82
|
+
test_h5f = load_test_datasets(args)
|
|
83
|
+
test_idxs = generate_test_indices(args.random_seed, test_h5f)
|
|
84
|
+
|
|
85
|
+
model, params = initialize_model_and_optim(device, args.flanking_size, args.pretrained_model, args.random_seed, args.test_target)
|
|
86
|
+
test_metric_files = create_metric_files(log_output_test_base)
|
|
87
|
+
print("test_metric_files: ", test_metric_files)
|
|
88
|
+
test_SpliceAI_Keras_model(model, test_h5f, test_idxs, args, params, test_metric_files)
|
|
89
|
+
# valid_epoch_keras(model, test_h5f, test_idxs, args.loss, params, test_metric_files, args.flanking_size, "Test")
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
File without changes
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import numpy as np
|
|
3
|
+
import torch
|
|
4
|
+
import torch.nn as nn
|
|
5
|
+
import torch.optim as optim
|
|
6
|
+
from torch.utils.data import TensorDataset, DataLoader
|
|
7
|
+
from tqdm import tqdm
|
|
8
|
+
import platform
|
|
9
|
+
from openspliceai.train_base.spliceai import *
|
|
10
|
+
from openspliceai.train_base.utils import *
|
|
11
|
+
from openspliceai.constants import *
|
|
12
|
+
import time
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def initialize_model_and_optim(device, flanking_size, epochs, scheduler):
|
|
16
|
+
# Hyper-parameters:
|
|
17
|
+
# L: Number of convolution kernels
|
|
18
|
+
# W: Convolution window size in each residual unit
|
|
19
|
+
# AR: Atrous rate in each residual unit
|
|
20
|
+
L = 32
|
|
21
|
+
N_GPUS = 2
|
|
22
|
+
W = np.asarray([11, 11, 11, 11])
|
|
23
|
+
AR = np.asarray([1, 1, 1, 1])
|
|
24
|
+
BATCH_SIZE = 18*N_GPUS
|
|
25
|
+
if int(flanking_size) == 80:
|
|
26
|
+
W = np.asarray([11, 11, 11, 11])
|
|
27
|
+
AR = np.asarray([1, 1, 1, 1])
|
|
28
|
+
BATCH_SIZE = 18*N_GPUS
|
|
29
|
+
elif int(flanking_size) == 400:
|
|
30
|
+
W = np.asarray([11, 11, 11, 11, 11, 11, 11, 11])
|
|
31
|
+
AR = np.asarray([1, 1, 1, 1, 4, 4, 4, 4])
|
|
32
|
+
BATCH_SIZE = 18*N_GPUS
|
|
33
|
+
elif int(flanking_size) == 2000:
|
|
34
|
+
W = np.asarray([11, 11, 11, 11, 11, 11, 11, 11,
|
|
35
|
+
21, 21, 21, 21])
|
|
36
|
+
AR = np.asarray([1, 1, 1, 1, 4, 4, 4, 4,
|
|
37
|
+
10, 10, 10, 10])
|
|
38
|
+
BATCH_SIZE = 12*N_GPUS
|
|
39
|
+
elif int(flanking_size) == 10000:
|
|
40
|
+
W = np.asarray([11, 11, 11, 11, 11, 11, 11, 11,
|
|
41
|
+
21, 21, 21, 21, 41, 41, 41, 41])
|
|
42
|
+
AR = np.asarray([1, 1, 1, 1, 4, 4, 4, 4,
|
|
43
|
+
10, 10, 10, 10, 25, 25, 25, 25])
|
|
44
|
+
BATCH_SIZE = 6*N_GPUS
|
|
45
|
+
CL = 2 * np.sum(AR*(W-1))
|
|
46
|
+
print("\033[1mContext nucleotides: %d\033[0m" % (CL))
|
|
47
|
+
print("\033[1mSequence length (output): %d\033[0m" % (SL))
|
|
48
|
+
model = SpliceAI(L, W, AR).to(device)
|
|
49
|
+
print(model, file=sys.stderr)
|
|
50
|
+
# optimizer = optim.Adam(model.parameters(), lr=1e-3)
|
|
51
|
+
optimizer = torch.optim.AdamW(model.parameters(), lr=1e-3)
|
|
52
|
+
# scheduler = get_cosine_schedule_with_warmup(optimizer, 1000, train_size * EPOCH_NUM)
|
|
53
|
+
if scheduler == "MultiStepLR":
|
|
54
|
+
scheduler_obj = optim.lr_scheduler.MultiStepLR(optimizer, milestones=[epochs-5, epochs-4, epochs-3, epochs-2, epochs-1], gamma=0.5)
|
|
55
|
+
elif scheduler == "CosineAnnealingWarmRestarts":
|
|
56
|
+
scheduler_obj = torch.optim.lr_scheduler.CosineAnnealingWarmRestarts(
|
|
57
|
+
optimizer, T_0=5, T_mult=1, eta_min=1e-5, last_epoch=-1)
|
|
58
|
+
params = {'L': L, 'W': W, 'AR': AR, 'CL': CL, 'SL': SL, 'BATCH_SIZE': BATCH_SIZE, 'N_GPUS': N_GPUS}
|
|
59
|
+
return model, optimizer, scheduler_obj, params
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def train(args):
|
|
63
|
+
print("Running OpenSpliceAI with 'train' mode")
|
|
64
|
+
device = setup_environment(args)
|
|
65
|
+
model_output_base, log_output_train_base, log_output_val_base, log_output_test_base = initialize_paths(args)
|
|
66
|
+
train_h5f, test_h5f, batch_num = load_datasets(args)
|
|
67
|
+
train_idxs, val_idxs, test_idxs = generate_indices(batch_num, args.random_seed, test_h5f)
|
|
68
|
+
model, optimizer, scheduler, params = initialize_model_and_optim(device, args.flanking_size, args.epochs, args.scheduler)
|
|
69
|
+
params["RANDOM_SEED"] = args.random_seed
|
|
70
|
+
train_metric_files = create_metric_files(log_output_train_base)
|
|
71
|
+
valid_metric_files = create_metric_files(log_output_val_base)
|
|
72
|
+
test_metric_files = create_metric_files(log_output_test_base)
|
|
73
|
+
train_model(model, optimizer, scheduler, train_h5f, test_h5f,
|
|
74
|
+
train_idxs, val_idxs, test_idxs, model_output_base, args, device, params, train_metric_files, valid_metric_files, test_metric_files)
|
|
75
|
+
train_h5f.close()
|
|
76
|
+
test_h5f.close()
|
|
File without changes
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import torch
|
|
2
|
+
import numpy as np
|
|
3
|
+
import torch.nn as nn
|
|
4
|
+
import torch.nn.functional as F
|
|
5
|
+
|
|
6
|
+
class ResidualUnit(nn.Module):
|
|
7
|
+
def __init__(self, l, w, ar):
|
|
8
|
+
super().__init__()
|
|
9
|
+
self.batchnorm1 = nn.BatchNorm1d(l)
|
|
10
|
+
self.batchnorm2 = nn.BatchNorm1d(l)
|
|
11
|
+
self.relu1 = nn.LeakyReLU(0.1)
|
|
12
|
+
self.relu2 = nn.LeakyReLU(0.1)
|
|
13
|
+
self.conv1 = nn.Conv1d(l, l, w, dilation=ar, padding=(w-1)*ar//2)
|
|
14
|
+
self.conv2 = nn.Conv1d(l, l, w, dilation=ar, padding=(w-1)*ar//2)
|
|
15
|
+
|
|
16
|
+
def forward(self, x, y):
|
|
17
|
+
out = self.conv1(self.relu1(self.batchnorm1(x)))
|
|
18
|
+
out = self.conv2(self.relu2(self.batchnorm2(out)))
|
|
19
|
+
return x + out, y
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class Cropping1D(nn.Module):
|
|
23
|
+
def __init__(self, cropping):
|
|
24
|
+
super().__init__()
|
|
25
|
+
self.cropping = cropping
|
|
26
|
+
|
|
27
|
+
def forward(self, x):
|
|
28
|
+
return x[:, :, self.cropping[0]:-self.cropping[1]] if self.cropping[1] > 0 else x[:, :, self.cropping[0]:]
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class Skip(nn.Module):
|
|
32
|
+
def __init__(self, l):
|
|
33
|
+
super().__init__()
|
|
34
|
+
self.conv = nn.Conv1d(l, l, 1)
|
|
35
|
+
|
|
36
|
+
def forward(self, x, y):
|
|
37
|
+
return x, self.conv(x) + y
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class SpliceAI(nn.Module):
|
|
41
|
+
def __init__(self, L, W, AR):
|
|
42
|
+
super(SpliceAI, self).__init__()
|
|
43
|
+
self.initial_conv = nn.Conv1d(4, L, 1)
|
|
44
|
+
self.initial_skip = Skip(L)
|
|
45
|
+
self.residual_units = nn.ModuleList()
|
|
46
|
+
for i, (w, r) in enumerate(zip(W, AR)):
|
|
47
|
+
self.residual_units.append(ResidualUnit(L, w, r))
|
|
48
|
+
if (i+1) % 4 == 0:
|
|
49
|
+
self.residual_units.append(Skip(L))
|
|
50
|
+
self.final_conv = nn.Conv1d(L, 3, 1)
|
|
51
|
+
self.CL = 2 * np.sum(AR * (W - 1))
|
|
52
|
+
self.crop = Cropping1D((self.CL//2, self.CL//2))
|
|
53
|
+
|
|
54
|
+
def forward(self, x):
|
|
55
|
+
x = self.initial_conv(x)
|
|
56
|
+
x, skip = self.initial_skip(x, 0)
|
|
57
|
+
for m in self.residual_units:
|
|
58
|
+
x, skip = m(x, skip)
|
|
59
|
+
final_x = self.crop(skip)
|
|
60
|
+
out = self.final_conv(final_x)
|
|
61
|
+
return F.softmax(out, dim=1)
|