9/16/2024
Pytorch model to mlir -> llvm -> executable file on Mac book m1
1/30/2024
checking torch + cuda installed correctly
Run this script
.
..
If return 'False' then you need to fix your system.
Thank you.
6/02/2023
torch tensor padding example code:
refer to code:
.
..
www.marearts.com
Thank you. 🙇🏻♂️
2/17/2023
How to print the full contents of a PyTorch tensor
refer to code:
..
..
In this example, we set the precision to 10 to display up to 10 decimal places, and set threshold, edgeitems, linewidth, and profile to None to display all the elements of the tensor. You can adjust these settings to your preference, depending on the size and precision of your tensor.
Thank you.
www.marearts.com
1/25/2023
RuntimeError: CUDA error: CUBLAS_STATUS_INVALID_VALUE when calling `cublasSgemm( handle, opa, opb, m, n, k, &alpha, a, lda, b, ldb, &beta, c, ldc)`
I was suffering above (title) error during few hours.
The reason is wrong cuda version installed with pytorch.
My cuda version is 11.6, but install version is 11.7.
So I print it -> "torch.__version__"
It returend -> "1.13.1+cu117"
You can check your cuda version using this command
> nvidia-smi
so, remove all torch, torchvision packaged
> pip uninstall torch torchvision
and install again
ex)
pip3 install torch torchvision torchaudio --extra-index-url \https://download.pytorch.org/whl/cu116
Then it works well.
Thank you.
🙇🏻♂️
1/10/2023
SSLCertVerificationError when downloading pytorch model or datasets via torchvision
I tried to download resnet101 model via torchvision model
ex) torchvision.models.resnet101(pretrained=True)
But it has such a error
---------------------------------------------------------------------------
SSLCertVerificationError Traceback (most recent call last)
F........
This line would solve this issue :
..
..
Thank you.
www.marearts.com
4/17/2022
'your model' object has no attribute 'seek'. You can only torch.load from a file that is seekable. Please pre-load the data into a buffer like io.BytesIO and try to load from it instead.
I tired to save sub model in seq-to-seq model which is encoder part.
What I used for save and load is like follow code and I failed with error like title.
* Failed case
..
..
* error message
..
My solution is to use 'state_dict()' to save model.
Refer to bellow code which was solution for me.
..
..
Thank you.
www.marearts.com
4/11/2022
LSTM Autoencoder pytorch
Code
...
...
Test class and show summary
..
..
output
..
Refer to my ugly drawing
Thank you.
www.marearts.com
time-distributed dense (TDD, TimeDistributed) layer in PyTorch
refer to code:
..
..
Thank you.
www.marearts.com
torch repeat example
Refer to code
..
..
>>
input :torch.Size([100, 140, 5]), repeat:torch.Size([100, 140, 5]) input :torch.Size([100, 140, 5]), repeat:torch.Size([100, 1400, 5]) input :torch.Size([100, 140, 5]), repeat:torch.Size([100, 140, 50]) input :torch.Size([100, 140, 5]), repeat:torch.Size([1000, 140, 5])
Thank you.
www.marearts.com
4/10/2022
pytorch module list example
ex1)
..
ex2)
..
print module list
>
ModuleList( (0): Linear(in_features=10, out_features=10, bias=True) (1): Linear(in_features=10, out_features=10, bias=True) (2): Linear(in_features=10, out_features=10, bias=True) (3): Linear(in_features=10, out_features=10, bias=True) (4): Linear(in_features=10, out_features=10, bias=True) (5): Linear(in_features=10, out_features=10, bias=True) (6): Linear(in_features=10, out_features=10, bias=True) (7): Linear(in_features=10, out_features=10, bias=True) (8): Linear(in_features=10, out_features=10, bias=True) (9): Linear(in_features=10, out_features=10, bias=True) )
4/08/2022
Warning: find_unused_parameters=True was specified in DDP constructor, but did not find any unused parameters. This flag results in an extra traversal of the autograd graph every iteration, which can adversely affect performance
Try #1
..
Try #2
..
Thank you.
4/04/2022
skip sanity val check in pytorch lightning
set trainer like this:
2/25/2022
list tensor to batch tensor, Pytorch
4 length list tensor -> 4 x 200 x 200 x 3 tensor
--
--
output
--
Thank you.
www.marearts.com
🙇🏻♂️
12/02/2021
How to combine multiple criterions to a loss function? Multiple loss function for single model.
You can simply reference below code:
ex1)
b = nn.MSELoss()(output_x, x_labels) a = nn.CrossEntropyLoss()(output_y, y_labels) loss = a + b loss.backward()
ex2)
b = nn.MSELoss() a = nn.CrossEntropyLoss() loss_a = a(output_x, x_labels) loss_b = b(output_y, y_labels) loss = loss_a + loss_b loss.backward()
And there are many opinions in here:
https://discuss.pytorch.org/t/how-to-combine-multiple-criterions-to-a-loss-function/348/27
Thank you.
www.marearts.com
🙇🏻♂️
9/22/2021
pytorch cuda definition
Their syntax varies slightly, but they are equivalent:
⠀ |
.to(name) |
.to(device) |
.cuda() |
CPU |
to('cpu') |
to(torch.device('cpu')) |
cpu() |
Current GPU |
to('cuda') |
to(torch.device('cuda')) |
cuda() |
Specific GPU |
to('cuda:1') |
to(torch.device('cuda:1')) |
cuda(device=1) |
Note: the current cuda device is 0 by default, but this can be set with torch.cuda.set_device().
7/24/2021
check pytorch, Tensorflow can use GPU
test tensorflow which can use GPU
#method 1
import tensorflow as tf
tf.test.is_built_with_cuda()
> Ture
#method 2
from tensorflow.python.client import device_lib
device_lib.list_local_devices()
> ..
test pytorch can use GPU
#method 3
import torch
torch.cuda.is_available()
>>> True
torch.cuda.current_device()
>>> 0
torch.cuda.device(0)
>>> <torch.cuda.device at 0x7efce0b03be0>
torch.cuda.device_count()
>>> 1
torch.cuda.get_device_name(0)
>>> 'GeForce GTX 950M'
Thank you.
www.MareArts.com
9/23/2020
Pytorch, Infinite DataLoader using iter & next
8/20/2020
RuntimeError: set_sizes_contiguous is not allowed on Tensor created from .data or .detach(), in Pytorch 1.1.0
change old -> new
old
NEW
-
Logistic Classifier The logistic classifier is similar to equation of the plane. W is weight vector, X is input vector and y is output...
-
I use MOG2 algorithm to background subtraction. The process is resize to small for more fast processing to blur for avoid noise affectio...
-
This is data acquisition source code of LMS511(SICK co.) Source code is made by MFC(vs 2008). The sensor is communicated by TCP/IP. ...
-
Background subtractor example souce code. OpenCV support about 3 types subtraction algorithm. Those are MOG, MOG2, GMG algorithms. Det...
-
Image size of origin is 320*240. Processing time is 30.96 second took. The result of stitching The resul...
-
Created Date : 2009.10. Language : C++ Tool : Visual Studio C++ 2008 Library & Utilized : Point Grey-FlyCapture, Triclops, OpenCV...
-
As you can see in the following video, I created a class that stitching n cameras in real time. https://www.youtube.com/user/feelmare/sear...
-
The MNIST dataset is a dataset of handwritten digits, comprising 60 000 training examples and 10 000 test examples. The dataset can be downl...
-
This post is about how to copy Mat data to vector and copy vector data to Mat. Reference this example source code. printf ( "/////...
-
This example source code is to extract HOG feature from images. And save descriptors to XML file. The source code explain how to use HOGD...