This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| help(model) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| model.state_dict() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| for name, param in model.named_parameters(): | |
| print(name, ':', param.requires_grad) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| for name, param in model.named_parameters(): | |
| if name in ['fc.weight', 'fc.bias']: | |
| param.requires_grad = True | |
| else: | |
| param.requires_grad = False |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| for name, param in model.named_parameters(): | |
| print('name: ', name) | |
| print(type(param)) | |
| print('param.shape: ', param.shape) | |
| print('param.requires_grad: ', param.requires_grad) | |
| print('=====') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| model = NeuralNet() | |
| print(model) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import torch | |
| import torch.nn as nn |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class NeuralNet(nn.Module): | |
| def __init__(self): | |
| super(NeuralNet, self).__init__() | |
| self.sequential = nn.Sequential(nn.Conv2d(1, 32, 5), | |
| nn.Conv2d(32, 64, 5), | |
| nn.Dropout(0.3)) | |
| self.layer1 = nn.Conv2d(64, 128, 5) | |
| self.layer2 = nn.Conv2d(128, 256, 5) | |
| self.fc = nn.Linear(256*34*34, 128) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| iterations = 100 | |
| stop=[False]*k | |
| for n in range(iterations): | |
| # iterate over the data points and assign them to one of the k clusters | |
| print('iteration number {}'.format(n)) | |
| for i, (x, y) in enumerate(zip(x_data, y_data)): | |
| cluster_index= assign_cluster(x, y, kcenters) | |
| # updating the color_list for all the data points on the basis of the newly assigned clusters to them. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def get_mean_shit_value(old_point, new_point): | |
| mean_shift_value = np.sqrt( np.square(old_point[0] - new_point[0]) + np.square(old_point[1] - new_point[1]) ) | |
| return mean_shift_value |