-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sourcery refactored main branch #1
base: main
Are you sure you want to change the base?
Conversation
|
||
## Load the models one by one. | ||
print("Preparing the encoder, the synthesizer and the vocoder...") | ||
encoder.load_model(enc_model_fpath) | ||
synthesizer = Synthesizer(syn_model_fpath) | ||
vocoder.load_model(voc_model_fpath) | ||
|
||
|
||
texts_array = [] | ||
with open('documentation/voice_cloning/sample_text.txt', 'r') as voice_cloning_para: | ||
texts_array = voice_cloning_para.readlines() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function voice_creation_build
refactored with the following changes:
- Replace assignment with augmented assignment (
aug-assign
)
if isinstance(fpath_or_wav, str) or isinstance(fpath_or_wav, Path): | ||
if isinstance(fpath_or_wav, (str, Path)): | ||
wav, source_sr = librosa.load(str(fpath_or_wav), sr=None) | ||
else: | ||
wav = fpath_or_wav | ||
|
||
# Resample the wav if needed | ||
if source_sr is not None and source_sr != sampling_rate: | ||
wav = librosa.resample(wav, source_sr, sampling_rate) | ||
|
||
# Apply the preprocessing: normalize volume and shorten long silences | ||
if normalize: | ||
wav = normalize_volume(wav, audio_norm_target_dBFS, increase_only=True) | ||
if webrtcvad and trim_silence: | ||
wav = trim_long_silences(wav) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function preprocess_wav
refactored with the following changes:
- Merge isinstance calls (
merge-is-instance
)
|
||
frames = torch.from_numpy(frames_batch).to(_device) | ||
embed = _model.forward(frames).detach().cpu().numpy() | ||
return embed | ||
return _model.forward(frames).detach().cpu().numpy() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function embed_frames_batch
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
self.sample_data = dict() | ||
self.sample_data = {} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function DatasetLog.__init__
refactored with the following changes:
- Replace dict() with {} (
dict-literal
)
if not param_name in self.sample_data: | ||
if param_name not in self.sample_data: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function DatasetLog.add_sample
refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan
)
y = g * F.relu(x1) + (1. - g) * x | ||
return y | ||
return g * F.relu(x1) + (1. - g) * x |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function HighwayNetwork.forward
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
if speaker_embedding.dim() == 1: | ||
idx = 0 | ||
else: | ||
idx = 1 | ||
|
||
idx = 0 if speaker_embedding.dim() == 1 else 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Encoder.add_speaker_embedding
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
for i in range(num_highways): | ||
for _ in range(num_highways): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function CBHG.__init__
refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore
)
parameters = sum([np.prod(p.size()) for p in parameters]) / 1_000_000 | ||
parameters = sum(np.prod(p.size()) for p in parameters) / 1_000_000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Tacotron.num_params
refactored with the following changes:
- Replace unneeded comprehension with generator (
comprehension-to-generator
)
return "\n".join([" ".join(seq[i:i + max_words]) for i in range(0, len(seq), max_words)]) | ||
return "\n".join( | ||
" ".join(seq[i:i + max_words]) for i in range(0, len(seq), max_words)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function split_title_line
refactored with the following changes:
- Replace unneeded comprehension with generator (
comprehension-to-generator
)
def decode_mu_law(y, mu, from_labels=True) : | ||
def decode_mu_law(y, mu, from_labels=True): | ||
if from_labels: | ||
y = label_2_float(y, math.log2(mu)) | ||
mu = mu - 1 | ||
x = np.sign(y) / mu * ((1 + mu) ** np.abs(y) - 1) | ||
return x | ||
return np.sign(y) / mu * ((1 + mu) ** np.abs(y) - 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function decode_mu_law
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
bar = '' | ||
for i in range(size): | ||
bar += '█' if i <= done else '░' | ||
return bar | ||
return ''.join('█' if i <= done else '░' for i in range(size)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function progbar
refactored with the following changes:
- Use str.join() instead of for loop (
use-join
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
)
def simple_table(item_tuples) : | ||
def simple_table(item_tuples): | ||
|
||
border_pattern = '+---------------------------------------' | ||
whitespace = ' ' | ||
|
||
headings, cells, = [], [] | ||
|
||
for item in item_tuples : | ||
for item in item_tuples: | ||
|
||
heading, cell = str(item[0]), str(item[1]) | ||
|
||
pad_head = True if len(heading) < len(cell) else False | ||
pad_head = len(heading) < len(cell) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function simple_table
refactored with the following changes:
- Simplify boolean if expression (
boolean-if-exp-identity
)
def time_since(started) : | ||
def time_since(started): | ||
elapsed = time.time() - started | ||
m = int(elapsed // 60) | ||
s = int(elapsed % 60) | ||
if m >= 60 : | ||
h = int(m // 60) | ||
m = m % 60 | ||
return f'{h}h {m}m {s}s' | ||
else : | ||
if m < 60: | ||
return f'{m}m {s}s' | ||
|
||
h = int(m // 60) | ||
m %= 60 | ||
return f'{h}h {m}m {s}s' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function time_since
refactored with the following changes:
- Replace assignment with augmented assignment (
aug-assign
) - Swap if/else branches (
swap-if-else-branches
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
)
|
||
if normalize: | ||
mel = mel / hp.mel_max_abs_value | ||
mel = torch.from_numpy(mel[None, ...]) | ||
wav = _model.generate(mel, batched, target, overlap, hp.mu_law, progress_callback) | ||
return wav | ||
return _model.generate( | ||
mel, batched, target, overlap, hp.mu_law, progress_callback | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function infer_waveform
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
if torch.cuda.is_available(): | ||
mels = mels.cuda() | ||
else: | ||
mels = mels.cpu() | ||
mels = mels.cuda() if torch.cuda.is_available() else mels.cpu() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function WaveRNN.generate
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
if side == 'before' or side == 'both': | ||
if side in ['before', 'both']: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function WaveRNN.pad_tensor
refactored with the following changes:
- Replace multiple comparisons of same variable with
in
operator (merge-comparisons
)
parameters = sum([np.prod(p.size()) for p in parameters]) / 1_000_000 | ||
parameters = sum(np.prod(p.size()) for p in parameters) / 1_000_000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function WaveRNN.num_params
refactored with the following changes:
- Replace unneeded comprehension with generator (
comprehension-to-generator
)
image_list = list() | ||
image_list = [] | ||
|
||
if not 'user_id' in user_dict: | ||
if 'user_id' not in user_dict: | ||
raise create_error_message('Bad Request') | ||
|
||
if user_dict['image_id'] == '': | ||
image_list = user_table.find_one({'_id': ObjectId(user_dict['user_id'])})['images'] | ||
image_table.delete(image_list) | ||
return user_table.delete_one({'_id': ObjectId(user_dict['user_id'])}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function delete
refactored with the following changes:
- Replace list() with [] (
list-literal
) - Simplify logical expression using De Morgan identities (
de-morgan
)
return True if user_table.find_one({'name': user.get_name()}) else False | ||
return bool(user_table.find_one({'name': user.get_name()})) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function user_already_exists
refactored with the following changes:
- Simplify boolean if expression (
boolean-if-exp-identity
)
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 0.14%.
Here are some functions in these files that still need a tune-up:
Legend and ExplanationThe emojis denote the absolute quality of the code:
The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request. Please see our documentation here for details on how these metrics are calculated. We are actively working on this report - lots more documentation and extra metrics to come! Let us know what you think of it by mentioning @sourcery-ai in a comment. |
Branch
main
refactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
main
branch, then run: