24
votes
Accepted
Intersection over Union for rotated rectangles
1. Review
The large bounty suggests that getting a review of this code is important. But there are some other things you could have done to make reviewing this code more productive:
Give us some more ...
9
votes
Intersection over Union for rotated rectangles
There are two main reasons why your program is slow and using huge amounts of memory:
You are using a 768×768 pixel image for each overlap calculation
You are checking each anchor box against each red ...
7
votes
A .py utility file for neural network learing rate policies
Overall I rather like this. It's a nice way to think about "configurable functions". Minor stuff:
Due to order of operations, the parens around ...
5
votes
Accepted
Class for validating code in different Conda environments with PyTorch
version hardcodes
To dry
up run_test_old_and_new_code(),
it looks like we want a helper
that accepts a version number
such as ...
5
votes
Accepted
Computing inverse of modified matrix using Sherman-Morrison formula
I'll be disregarding torch, as this doesn't have a lot to do with machine learning specifically. Let's instead develop a demonstration in more generic numerical libraries, Numpy and Scipy. Most of the ...
5
votes
Accepted
PyTorch Unit-testing in Python
Since you are asking about PyTorch's capabilities you are not taking advantage of, you might want to use:
torch.linspace(-10,0,300) instead of ...
4
votes
Accepted
PyTorch Vectorized Implementation for Thresholding and Computing Jaccard Index
I think a different approach is needed to achieve a better performance. The current approach recomputes the Jaccard similarity from scratch for each possible threshold value. However, going from one ...
4
votes
Accepted
Loops in PyTorch Implementation
I don't have many improvements to offer-- just one major one. Like you suspected, your implementation is not efficient. This is because using a double for loop to set a Torch/NumPy array is not the ...
4
votes
Pytorch code running slow for Deep Q learning (Reinforcement Learning)
What I can do for you and give you some general suggestions:
Use library like Nuba or similar;
try Pypy is a JIT compiler;
if is possible use C or C++ modules.
and here the code with some ...
4
votes
3
votes
Transformer based on pytorch nn.Transformer to predict protein secondary structure
Here are some minor coding style suggestions.
Documentation
The PEP 8 style guide recommends
adding docstrings for classes and functions.
Simpler
The following:
...
3
votes
Accepted
String art program in Python using PyTorch
Strategies to speed up the code:
Instead of computing all the lines in one large array, then picking one, you should compute one line at the time, and keep only the best one iteratively. Loops in ...
3
votes
Kaggle Notebook for Identifying House Plants
module docstring
First, in any language, avoid repeated "----" or "===="
ASCII art in comments.
Prefer to use whatever tools the language
offers in order to better organize your ...
3
votes
Accepted
Kaggle Notebook for Identifying House Plants
Overview
The code layout and organization is good, the function docstrings are helpful
and you used meaningful names for functions and variables.
Comments
It is good that you added comments at the top ...
3
votes
Accepted
Randomly rotate an image through right angles
types are for documentation
tried to include types
You did great.
Please understand that type hint annotations are entirely optional,
though the Gentle Reader will love them.
The cPython interpreter ...
3
votes
Accepted
increase efficiency of loops and element-wise operations in PyTorch implementation
A few hints for improving efficiency:
When W[i, j] == 0, B equals to W so ...
2
votes
PyTorch Vectorized Implementation for Thresholding and Computing Jaccard Index
Thanks to the answer of @GZ0, the performance of this code snippet is now around 0.0344s on a GPU and around 0.2511s on a CPU. The implementation of @GZ0's algorithm is attached. Please do not ...
2
votes
Iterating over symmetric matrix
It's not clear whether you need to iterate over these values just once, or in several different places in the code.
If the latter, then you probably want to encapsulate the logic in a reusable ...
2
votes
Loss function in python is a bit cumbersome
It looks like you need to calculate the same thing over and over again. Instead of doing this separately for the positive, the negative and all labels (not sure that is the correct word), you could do ...
2
votes
resnet with pytorch
import torchvision.transforms as transforms
To make your code easier to read, use from imports:
...
2
votes
Neural network that determines the gender of a word
Efficiency
In the main function while loop, the 3 separate if statements
should be combined ...
2
votes
Accepted
One-layer linear neural network to solve a regression problem in PyTorch
Should I import torch and its submodules in every file? Is it good practice to import a library so many times?
Yes.
Yes.
If you need it, import it.
Don't worry, ...
2
votes
I have a pytorch module that takes in some parameters and predicts the difference between one of it inputs and the target
computing a discarded result
Please don't write code like this:
def greet(name):
42
name + " is cool."
print(f"Hello {name}!")
Yes, ...
2
votes
Accepted
Video Frame-by-Frame Deraining with MFDNet
I don't really see the need to use numpy as a buffer between ffmpeg and torch as ...
2
votes
Class for validating code in different Conda environments with PyTorch
The previous answer was thorough, but here are some additional suggestions.
DRY
Your LOGGER info and ...
1
vote
Accepted
Follow up - Deep Learning Project for House Plant Identification on Kaggle Notebook
In function train_step:
for images, labels in dataloader:
images, labels = images.to(device), labels.to(device)
it seems ...
1
vote
Video Frame-by-Frame Deraining with MFDNet
Documentation
It is great that you have a docstring describing the function.
It would be good to add a description of the model_restoration
argument to the doctring,...
1
vote
Neural network that determines the gender of a word
These three tests are supposed to be exhaustive:
...
1
vote
Accepted
Set min value of each row of a tensor to zero without using explicit loops
Not much of a code review, but this should work:
def zero_min(x):
y = x.clone()
y[torch.arange(x.shape[0]), torch.argmin(x, dim=1)] = 0
return y
In ...
1
vote
Iterating over symmetric matrix
I have a symmetric matrix, and I want to loop over its elements
Well... no. You only want to loop over its lower triangle (equivalent to its upper triangle), and there are more direct ways:
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
pytorch × 29python × 27
machine-learning × 8
performance × 7
neural-network × 6
image × 3
python-3.x × 2
memory-optimization × 2
video × 2
cuda × 2
beginner × 1
unit-testing × 1
numpy × 1
validation × 1
matrix × 1
memory-management × 1
thread-safety × 1
computational-geometry × 1
graphics × 1
ai × 1
vectorization × 1
context-manager × 1
type-hinting × 1