Sourcery Starbot ⭐ refactored undo76/PyTorch-GAN#1
Sourcery Starbot ⭐ refactored undo76/PyTorch-GAN#1SourceryAI wants to merge 1 commit intoundo76:masterfrom
Conversation
SourceryAI
left a comment
There was a problem hiding this comment.
Due to GitHub API limits, only the first 60 comments can be shown.
| img_shape = (opt.channels, opt.img_size, opt.img_size) | ||
|
|
||
| cuda = True if torch.cuda.is_available() else False | ||
| cuda = bool(torch.cuda.is_available()) |
There was a problem hiding this comment.
Lines 36-36 refactored with the following changes:
- Simplify boolean if expression (
boolean-if-exp-identity)
| sampled_z = Variable(Tensor(np.random.normal(0, 1, (mu.size(0), opt.latent_dim)))) | ||
| z = sampled_z * std + mu | ||
| return z | ||
| return sampled_z * std + mu |
There was a problem hiding this comment.
Function reparameterization refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| z = reparameterization(mu, logvar) | ||
| return z | ||
| return reparameterization(mu, logvar) |
There was a problem hiding this comment.
Function Encoder.forward refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| img = img_flat.view(img_flat.shape[0], *img_shape) | ||
| return img | ||
| return img_flat.view(img_flat.shape[0], *img_shape) |
There was a problem hiding this comment.
Function Decoder.forward refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| validity = self.model(z) | ||
| return validity | ||
| return self.model(z) |
There was a problem hiding this comment.
Function Discriminator.forward refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| print(opt) | ||
|
|
||
| cuda = True if torch.cuda.is_available() else False | ||
| cuda = bool(torch.cuda.is_available()) |
There was a problem hiding this comment.
Lines 39-39 refactored with the following changes:
- Simplify boolean if expression (
boolean-if-exp-identity)
| x = self.model(x) | ||
| out = torch.cat((x, skip_input), 1) | ||
| return out | ||
| return torch.cat((x, skip_input), 1) |
There was a problem hiding this comment.
Function UNetUp.forward refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| img_shape = (opt.channels, opt.img_size, opt.img_size) | ||
|
|
||
| cuda = True if torch.cuda.is_available() else False | ||
| cuda = bool(torch.cuda.is_available()) |
There was a problem hiding this comment.
Lines 36-36 refactored with the following changes:
- Simplify boolean if expression (
boolean-if-exp-identity)
| d_in = torch.cat((img.view(img.size(0), -1), self.label_embedding(labels)), -1) | ||
| validity = self.model(d_in) | ||
| return validity | ||
| return self.model(d_in) |
There was a problem hiding this comment.
Function Discriminator.forward refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| for m in net.modules(): | ||
| if isinstance(m, nn.Conv2d): | ||
| m.weight.data.normal_(0, 0.02) | ||
| m.bias.data.zero_() | ||
| elif isinstance(m, nn.ConvTranspose2d): | ||
| m.weight.data.normal_(0, 0.02) | ||
| m.bias.data.zero_() | ||
| elif isinstance(m, nn.Linear): | ||
| if isinstance(m, (nn.Conv2d, nn.ConvTranspose2d, nn.Linear)): | ||
| m.weight.data.normal_(0, 0.02) | ||
| m.bias.data.zero_() |
There was a problem hiding this comment.
Function initialize_weights refactored with the following changes:
- Merge duplicate blocks in conditional (
merge-duplicate-blocks) - Remove redundant conditional (
remove-redundant-if) - Merge isinstance calls (
merge-is-instance)
| # Get output | ||
| validity = self.model(img) | ||
| return validity | ||
| return self.model(img) |
There was a problem hiding this comment.
Function Discriminator_CNN.forward refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
This removes the following comments ( why? ):
# Get output
| cuda = True if torch.cuda.is_available() else False | ||
| cuda = bool(torch.cuda.is_available()) |
There was a problem hiding this comment.
Lines 326-562 refactored with the following changes:
- Hoist statements out of for/while loops (
hoist-statement-from-loop) - Simplify boolean if expression (
boolean-if-exp-identity) - Simplify sequence comparison (
simplify-len-comparison) - Replace x * x with x ** 2 (
square-identity)
| img_shape = (opt.channels, opt.img_size, opt.img_size) | ||
|
|
||
| cuda = True if torch.cuda.is_available() else False | ||
| cuda = bool(torch.cuda.is_available()) |
There was a problem hiding this comment.
Lines 39-39 refactored with the following changes:
- Simplify boolean if expression (
boolean-if-exp-identity)
| if e.errno == errno.EEXIST: | ||
| pass | ||
| else: | ||
| if e.errno != errno.EEXIST: |
There was a problem hiding this comment.
Function MNISTM.download refactored with the following changes:
- Swap if/else to remove empty if body (
remove-pass-body)
| @@ -8,6 +8,7 @@ | |||
| 4. Run the sript using command 'python3 context_encoder.py' | |||
| """ | |||
|
|
|||
There was a problem hiding this comment.
Lines 49-49 refactored with the following changes:
- Simplify boolean if expression (
boolean-if-exp-identity)
| img_shape = (opt.channels, opt.img_size, opt.img_size) | ||
|
|
||
| cuda = True if torch.cuda.is_available() else False | ||
| cuda = bool(torch.cuda.is_available()) |
There was a problem hiding this comment.
Lines 35-35 refactored with the following changes:
- Simplify boolean if expression (
boolean-if-exp-identity)
| out = out.view(out.shape[0], 128, self.init_size, self.init_size) | ||
| img = self.conv_blocks(out) | ||
| return img | ||
| return self.conv_blocks(out) |
There was a problem hiding this comment.
Function Generator.forward refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| loss_pt = (torch.sum(similarity) - batch_size) / (batch_size * (batch_size - 1)) | ||
| return loss_pt | ||
| return (torch.sum(similarity) - batch_size) / (batch_size * (batch_size - 1)) |
There was a problem hiding this comment.
Function pullaway_loss refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| layers = [] | ||
| layers.append(nn.Conv2d(in_filters, out_filters, kernel_size=3, stride=1, padding=1)) | ||
| layers = [ | ||
| nn.Conv2d(in_filters, out_filters, kernel_size=3, stride=1, padding=1) | ||
| ] | ||
|
|
There was a problem hiding this comment.
Function Discriminator.__init__.discriminator_block refactored with the following changes:
- Merge append into list declaration (
merge-list-append)
| img_shape = (opt.channels, opt.img_size, opt.img_size) | ||
|
|
||
| cuda = True if torch.cuda.is_available() else False | ||
| cuda = bool(torch.cuda.is_available()) |
There was a problem hiding this comment.
Lines 35-35 refactored with the following changes:
- Simplify boolean if expression (
boolean-if-exp-identity)
| validity = self.model(img_flat) | ||
|
|
||
| return validity | ||
| return self.model(img_flat) |
There was a problem hiding this comment.
Function Discriminator.forward refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| print(opt) | ||
|
|
||
| cuda = True if torch.cuda.is_available() else False | ||
| cuda = bool(torch.cuda.is_available()) |
There was a problem hiding this comment.
Lines 38-38 refactored with the following changes:
- Simplify boolean if expression (
boolean-if-exp-identity)
| out = out.view(out.shape[0], 128, self.init_size, self.init_size) | ||
| img = self.conv_blocks(out) | ||
| return img | ||
| return self.conv_blocks(out) |
There was a problem hiding this comment.
Function Generator.forward refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| print(opt) | ||
|
|
||
| cuda = True if torch.cuda.is_available() else False | ||
| cuda = bool(torch.cuda.is_available()) |
There was a problem hiding this comment.
Lines 33-33 refactored with the following changes:
- Simplify boolean if expression (
boolean-if-exp-identity)
| out = out.view(out.shape[0], 128, self.init_size, self.init_size) | ||
| img = self.conv_blocks(out) | ||
| return img | ||
| return self.conv_blocks(out) |
There was a problem hiding this comment.
Function Generator.forward refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| validity = self.model(img) | ||
|
|
||
| return validity | ||
| return self.model(img) |
There was a problem hiding this comment.
Function Discriminator.forward refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| label = self.output_layer(feature_repr) | ||
| return label | ||
| return self.output_layer(feature_repr) |
There was a problem hiding this comment.
Function Classifier.forward refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| out = out.view(out.shape[0], 128, self.init_size, self.init_size) | ||
| img = self.conv_blocks(out) | ||
| return img | ||
| return self.conv_blocks(out) |
There was a problem hiding this comment.
Function Generator.forward refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| validity = self.adv_layer(out) | ||
|
|
||
| return validity | ||
| return self.adv_layer(out) |
There was a problem hiding this comment.
Function Discriminator.forward refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| print(opt) | ||
|
|
||
| cuda = True if torch.cuda.is_available() else False | ||
| cuda = bool(torch.cuda.is_available()) |
There was a problem hiding this comment.
Lines 34-34 refactored with the following changes:
- Simplify boolean if expression (
boolean-if-exp-identity)
Thanks for starring sourcery-ai/sourcery ✨ 🌟 ✨
Here's your pull request refactoring your most popular Python repo.
If you want Sourcery to refactor all your Python repos and incoming pull requests install our bot.
Review changes via command line
To manually merge these changes, make sure you're on the
masterbranch, then run: