code stringlengths 3 6.57k |
|---|
F.relu(self.deconv3(x) |
F.relu(self.deconv4(x) |
torch.sigmoid(self.conv5(x) |
ClusteringLayer(nn.Module) |
__init__(self, weights=None, alpha=1.0) |
super() |
__init__() |
torch.empty(1000, 1000) |
nn.init.xavier_uniform_(self.weights) |
forward(self, x) |
x.unsqueeze(1) |
torch.transpose(q, 1, 2) |
torch.sum(q, dim=1) |
set_weights(module, weights) |
isinstance(module, ClusteringLayer) |
CAE(nn.Module) |
__init__(self) |
super() |
__init__() |
CAE_ENC() |
CAE_DEC() |
ClusteringLayer() |
forward(self, x) |
self.enc(x) |
self.clus(h) |
self.dec(h) |
return (h, q, o) |
loss(q, p, o, gamma=0.1) |
nn.MSELoss(o) |
kl.kl_divergence(p, q) |
target_distribution(q) |
torch.sum(q, dim=0) |
torch.transpose(torch.transpose(q) |
torch.sum(weight, dim=1) |
transforms.ToTensor() |
transforms.Normalize((0.485, 0.456, 0.406) |
data.ConcatDataset((dataset1, dataset2) |
int(train_ratio * len(dataset) |
len(dataset) |
data.DataLoader(train_data, batch_size=128, shuffle=True) |
data.DataLoader(val_data, batch_size=128, shuffle=False) |
torch.device('cuda:0' if torch.cuda.is_available() |
CAE() |
to(device) |
nn.MSELoss() |
optim.Adam(model.parameters() |
float('inf') |
print('pretrain') |
range(tot_epochs) |
model.train() |
print('epoch {} of {}'.format(epoch + 1, tot_epochs) |
tqdm.tqdm(desc=desc.format(0) |
len(train_loader) |
enumerate(train_loader) |
img.to(device) |
optimizer.zero_grad() |
model(img) |
nn.MSELoss(out, img) |
loss.item() |
loss.backward() |
optimizer.step() |
desc.format(loss.item() |
pbar.update() |
print('loss: {}'.format(running_loss / len(train_loader) |
model.eval() |
torch.no_grad() |
enumerate(val_loader) |
val_img.to(device) |
model(val_img) |
nn.MSELoss(val_out, val_img) |
val_loss.item() |
len(val_loader) |
torch.save(model.state_dict() |
print('val loss: {}'.format(val_running_loss / len(val_loader) |
pbar.close() |
enumerate(train_loader) |
img.to(device) |
model(img) |
torch.cat((features, model(img) |
cluster.kMeans(n_clusters=1000, n_init=20) |
features.view(-1) |
kmeans.fit_predict(features) |
print('deep cklustering') |
range(int(maxiter) |
model.train() |
enumerate(train_loader) |
img.to(device) |
model(img) |
model(img) |
torch.cat((q, new_q) |
q.argmax(1) |
np.sum(pred != pred_last) |
np.copy(pred) |
print('delta_label ', delta_label, '< tol ', 0.001) |
print('Reached tolerance threshold. Stopping training.') |
print('epoch {} of {}'.format(epoch + 1, tot_epochs) |
tqdm.tqdm(desc=desc.format(0) |
len(train_loader) |
enumerate(train_loader) |
img.to(device) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.