Skip to content
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 master branch #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Nov 8, 2022

Branch master 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 master branch, then run:

git fetch origin sourcery/master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from soumickmj November 8, 2022 08:35
Comment on lines -136 to +149
if __name__ == "__main__" :
if __name__ == "__main__":
explain_out = os.path.join(explain_out, '0 Specific Subjects')
device = torch.device("cuda:0" if torch.cuda.is_available() and useCuda else "cpu")
model_names = []
for checkpoint in model_checkpoints:
model_names.append(os.path.basename(checkpoint).split('.')[0])

device = torch.device("cuda:0" if torch.cuda.is_available() and useCuda else "cpu")
model_names = [
os.path.basename(checkpoint).split('.')[0]
for checkpoint in model_checkpoints
]

if len(sys.argv) > 1:
modelID = int(sys.argv[1])
print("Only explaining Model ID : "+str(modelID) +" "+ model_names[modelID])
print(f"Only explaining Model ID : {modelID} {model_names[modelID]}")
model_names = [model_names[modelID]]
model_checkpoints = [model_checkpoints[modelID]]
print(str(len(model_checkpoints))+" model(s) explaining")
print(f"{len(model_checkpoints)} model(s) explaining")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 136-169 refactored with the following changes:

Comment on lines -115 to +121
if __name__ == "__main__" :
if __name__ == "__main__":
explain_out = os.path.join(explain_out, '0 Specific Subjects')
device = torch.device("cuda:0" if torch.cuda.is_available() and useCuda else "cpu")
model_names = []
for checkpoint in model_checkpoints:
model_names.append(os.path.basename(checkpoint).split('.')[0])

device = torch.device("cuda:0" if torch.cuda.is_available() and useCuda else "cpu")
model_names = [
os.path.basename(checkpoint).split('.')[0]
for checkpoint in model_checkpoints
]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 115-182 refactored with the following changes:


Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found the following improvement in Lines 133-133:

Comment on lines -82 to +83
if __name__ == "__main__" :
device = torch.device("cuda:0" if torch.cuda.is_available() and useCuda else "cpu")
if __name__ == "__main__":
device = torch.device("cuda:0" if torch.cuda.is_available() and useCuda else "cpu")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 82-110 refactored with the following changes:

Comment on lines -148 to +161
if __name__ == "__main__" :
if __name__ == "__main__":
explain_out = os.path.join(explain_out, '0 Specific Subjects')
device = torch.device("cuda:0" if torch.cuda.is_available() and useCuda else "cpu")
model_names = []
for checkpoint in model_checkpoints:
model_names.append(os.path.basename(checkpoint).split('.')[0])

device = torch.device("cuda:0" if torch.cuda.is_available() and useCuda else "cpu")
model_names = [
os.path.basename(checkpoint).split('.')[0]
for checkpoint in model_checkpoints
]

if len(sys.argv) > 1:
modelID = int(sys.argv[1])
print("Only explaining Model ID : "+str(modelID) +" "+ model_names[modelID])
print(f"Only explaining Model ID : {modelID} {model_names[modelID]}")
model_names = [model_names[modelID]]
model_checkpoints = [model_checkpoints[modelID]]
print(str(len(model_checkpoints))+" model(s) explaining")
print(f"{len(model_checkpoints)} model(s) explaining")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 148-302 refactored with the following changes:

Comment on lines -6 to +7
print(str(ex))

print(ex)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 6-44 refactored with the following changes:

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Nov 8, 2022

Sourcery Code Quality Report

✅  Merging this PR will increase code quality in the affected files by 0.61%.

Quality metrics Before After Change
Complexity 28.01 😞 26.33 😞 -1.68 👍
Method Length 690.67 ⛔ 683.50 ⛔ -7.17 👍
Working memory 41.47 ⛔ 41.20 ⛔ -0.27 👍
Quality 12.81% 13.42% 0.61% 👍
Other metrics Before After Change
Lines 1068 1064 -4
Changed files Quality Before Quality After Quality Change
explain_allclassifiers_captum.py 6.96% ⛔ 8.17% ⛔ 1.21% 👍
explain_allclassifiers_captum_bkup.py 6.25% ⛔ 7.34% ⛔ 1.09% 👍
explain_classifier_captum.py 14.22% ⛔ 14.22% ⛔ 0.00%
explain_classifier_visualCNN.py 24.98% ⛔ 24.99% ⛔ 0.01% 👍
fetch_activations_4NAP.py 8.40% ⛔ 9.35% ⛔ 0.95% 👍
scribble.py 41.86% 😞 42.56% 😞 0.70% 👍

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

0 participants