Skip to content

Commit

Permalink
Merge branch 'kl/stereo_and_scaling_fix' into 'master'
Browse files Browse the repository at this point in the history
Kl/stereo and scaling fix

See merge request machine-learning/bonito!180
  • Loading branch information
iiSeymour committed May 17, 2024
2 parents d4f6dd2 + a64e3ed commit a170b7c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
6 changes: 3 additions & 3 deletions bonito/crf/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,11 @@ def conv(c_in, c_out, ks, stride=1, bias=False, activation=None, norm=None):
return Convolution(c_in, c_out, ks, stride=stride, padding=ks//2, bias=bias, activation=activation, norm=norm)


def rnn_encoder(n_base, state_len, insize=1, stride=5, winlen=19, activation='swish', rnn_type='lstm', features=768, scale=5.0, blank_score=None, expand_blanks=True, num_layers=5, norm=None):
def rnn_encoder(n_base, state_len, insize=1, first_conv_size=4, stride=5, winlen=19, activation='swish', rnn_type='lstm', features=768, scale=5.0, blank_score=None, expand_blanks=True, num_layers=5, norm=None):
rnn = layers[rnn_type]
return Serial([
conv(insize, 4, ks=5, bias=True, activation=activation, norm=norm),
conv(4, 16, ks=5, bias=True, activation=activation, norm=norm),
conv(insize, first_conv_size, ks=5, bias=True, activation=activation, norm=norm),
conv(first_conv_size, 16, ks=5, bias=True, activation=activation, norm=norm),
conv(16, features, ks=winlen, stride=stride, bias=True, activation=activation, norm=norm),
Permute([2, 0, 1]),
*(rnn(features, features, reverse=(num_layers - i) % 2) for i in range(num_layers)),
Expand Down
2 changes: 2 additions & 0 deletions bonito/fast5.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ def __init__(self, read, filename, meta=False, do_trim=True, scaling_strategy=No
self.scaled = np.array(self.scaling * (raw + self.offset), dtype=np.float32)
self.num_samples = len(self.scaled)

self.scaling_strategy = ("quantile" if scaling_strategy is None else
scaling_strategy.get("strategy","quantile"))
self.shift, self.scale = bonito.reader.normalisation(self.scaled, scaling_strategy, norm_params)
self.trimmed_samples = bonito.reader.trim(self.scaled, threshold=self.scale * 2.4 + self.shift) if do_trim else 0
self.template_start = self.start + (self.trimmed_samples / self.sample_rate)
Expand Down
4 changes: 3 additions & 1 deletion bonito/pod5.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ def __init__(self, read, filename, meta=False, do_trim=True, scaling_strategy=No
self.scaling = self.calibration.scale
self.offset = self.calibration.offset
self.scaled = self.scaling * (self.raw.astype(np.float32) + self.offset)

self.scaling_strategy = ("quantile" if scaling_strategy is None else
scaling_strategy.get("strategy","quantile"))

self.shift, self.scale = bonito.reader.normalisation(self.scaled, scaling_strategy, norm_params)
self.trimmed_samples = bonito.reader.trim(self.scaled, threshold=self.scale * 2.4 + self.shift) if do_trim else 0

Expand Down
2 changes: 1 addition & 1 deletion bonito/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def tagdata(self):
f"f5:Z:{self.filename}",
f"sm:f:{self.shift}",
f"sd:f:{self.scale}",
f"sv:Z:quantile",
f"sv:Z:{self.scaling_strategy}",
]


Expand Down

0 comments on commit a170b7c

Please sign in to comment.