Skip to content

Instantly share code, notes, and snippets.

View sahandilshan's full-sized avatar

Sahan Dilshan sahandilshan

View GitHub Profile
@sahandilshan
sahandilshan / README.md
Last active September 14, 2023 12:49
Log formatting script for iam-cloud-diagnostics
  1. Save the script in a file, let's say format_logs.py.
  2. Make sure you have the logs.txt file that contains all the logs from the terminal that you have started the Product-IS. If you don't have it, create a new file and paste the logs into it.
  3. Open a terminal or command prompt.
  4. Navigate to the directory where you saved the format_logs.py and logs.txt files.
  5. Run the script by executing the following command:
python format_logs.py
  1. Note: Make sure you have Python installed on your system and the python command is available in your terminal or command prompt.
  2. The script will read the logs.txt file, format the only the logs iam-cloud-diagnostics, and print the formatted logs with colors in the terminal.
@sahandilshan
sahandilshan / Simple-MNIST-Model-Compression.py
Created February 22, 2021 13:02
A code snippet to train a model with MNIST dataset and compress it using pruning with PyTorch. Completed full code can be found on here https://github.com/sahandilshan/Simple-NN-Compression
from torch.nn.utils import prune
pruning_percenatage = 0.40
parameters_to_prune = (
(pruned_model.fc1, 'weight'),
(pruned_model.fc2, 'weight'),
(pruned_model.fc3, 'weight'),
(pruned_model.fc4, 'weight'),
)
prune.global_unstructured(
@sahandilshan
sahandilshan / Simple-MNIST-Model.py
Last active February 22, 2021 13:01
A code snippet to train a model with MNIST dataset and compress it using pruning with PyTorch. Completed full code can be found on here https://github.com/sahandilshan/Simple-NN-Compression
class Classifier(nn.Module):
def __init__(self):
super().__init__()
self.fc1 = nn.Linear(784, 256)
self.fc2 = nn.Linear(256, 128)
self.fc3 = nn.Linear(128, 64)
self.fc4 = nn.Linear(64, 10)
def forward(self, x):
# make sure input tensor is flattened