Skip to content

Instantly share code, notes, and snippets.

for name, param in model.named_parameters():
print(name, ':', param.requires_grad)
for name, param in model.named_parameters():
if name in ['fc.weight', 'fc.bias']:
param.requires_grad = True
else:
param.requires_grad = False
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('=====')
model = NeuralNet()
print(model)
import torch
import torch.nn as nn
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)
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.
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