add simple neural network and ResNet for Pytorch (Sourcery refactored)#2
add simple neural network and ResNet for Pytorch (Sourcery refactored)#2sourcery-ai[bot] wants to merge 1 commit into
Conversation
| x = self.fc2(x) | ||
| output = F.log_softmax(x, dim=1) | ||
| return output | ||
| return F.log_softmax(x, dim=1) |
There was a problem hiding this comment.
Function Net.forward refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| train_kwargs.update(cuda_kwargs) | ||
| test_kwargs.update(cuda_kwargs) | ||
| train_kwargs |= cuda_kwargs | ||
| test_kwargs |= cuda_kwargs |
There was a problem hiding this comment.
Function main refactored with the following changes:
- Merge dictionary updates via the union operator [×2] (
dict-assign-update-to-union)
| in_dim = 1 | ||
| else: | ||
| in_dim = 3 | ||
| in_dim = 1 if grayscale else 3 |
There was a problem hiding this comment.
Function ResNet.__init__ refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| layers = [] | ||
| layers.append(block(self.inplanes, planes, stride, downsample)) | ||
| layers = [block(self.inplanes, planes, stride, downsample)] | ||
| self.inplanes = planes * block.expansion | ||
| for i in range(1, blocks): | ||
| layers.append(block(self.inplanes, planes)) | ||
|
|
||
| layers.extend(block(self.inplanes, planes) for _ in range(1, blocks)) |
There was a problem hiding this comment.
Function ResNet._make_layer refactored with the following changes:
- Merge append into list declaration (
merge-list-append) - Replace unused for index with underscore (
for-index-underscore) - Replace a for append loop with list extend (
for-append-to-extend)
| model = ResNet(block=BasicBlock, | ||
| layers=[2, 2, 2, 2], | ||
| num_classes=NUM_CLASSES, | ||
| grayscale=GRAYSCALE) | ||
| return model | ||
| return ResNet( | ||
| block=BasicBlock, | ||
| layers=[2, 2, 2, 2], | ||
| num_classes=NUM_CLASSES, | ||
| grayscale=GRAYSCALE, | ||
| ) |
There was a problem hiding this comment.
Function resnet18 refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| for i, (features, targets) in enumerate(data_loader): | ||
|
|
||
| for features, targets in data_loader: |
There was a problem hiding this comment.
Function compute_accuracy refactored with the following changes:
- Remove unnecessary calls to
enumeratewhen the index is not used (remove-unused-enumerate)
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 0.28%.
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! Help us improve this quality report! |
Pull Request #1 refactored by Sourcery.
If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
NOTE: As code is pushed to the original Pull Request, Sourcery will
re-run and update (force-push) this Pull Request with new refactorings as
necessary. If Sourcery finds no refactorings at any point, this Pull Request
will be closed automatically.
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
benchmarks-Pythonbranch, then run:Help us improve this pull request!