text stringlengths 0 93.6k |
|---|
max_iter=conf.train.min_step) |
inv_lr_scheduler(param_lr_f, opt_c1, step, |
init_lr=conf.train.lr, |
max_iter=conf.train.min_step) |
img_s = data_s[0] |
label_s = data_s[1] |
img_t = data_t[0] |
index_t = data_t[2] |
img_s, label_s = Variable(img_s.cuda()), \ |
Variable(label_s.cuda()) |
img_t = Variable(img_t.cuda()) |
index_t = Variable(index_t.cuda()) |
if len(img_t) < batch_size: |
break |
if len(img_s) < batch_size: |
break |
opt_g.zero_grad() |
opt_c1.zero_grad() |
## Weight normalizztion |
C1.module.weight_norm() |
## Source loss calculation |
feat = G(img_s) |
out_s = C1(feat) |
loss_s = criterion(out_s, label_s) |
feat_t = G(img_t) |
out_t = C1(feat_t) |
feat_t = F.normalize(feat_t) |
### Calculate mini-batch x memory similarity |
feat_mat = lemniscate(feat_t, index_t) |
### We do not use memory features present in mini-batch |
feat_mat[:, index_t] = -1 / conf.model.temp |
### Calculate mini-batch x mini-batch similarity |
feat_mat2 = torch.matmul(feat_t, |
feat_t.t()) / conf.model.temp |
mask = torch.eye(feat_mat2.size(0), |
feat_mat2.size(0)).bool().cuda() |
feat_mat2.masked_fill_(mask, -1 / conf.model.temp) |
loss_nc = conf.train.eta * entropy(torch.cat([out_t, feat_mat, |
feat_mat2], 1)) |
loss_ent = conf.train.eta * entropy_margin(out_t, conf.train.thr, |
conf.train.margin) |
all = loss_nc + loss_s + loss_ent |
with amp.scale_loss(all, [opt_g, opt_c1]) as scaled_loss: |
scaled_loss.backward() |
opt_g.step() |
opt_c1.step() |
opt_g.zero_grad() |
opt_c1.zero_grad() |
lemniscate.update_weight(feat_t, index_t) |
if step % conf.train.log_interval == 0: |
print('Train [{}/{} ({:.2f}%)]\tLoss Source: {:.6f} ' |
'Loss NC: {:.6f} Loss ENS: {:.6f}\t'.format( |
step, conf.train.min_step, |
100 * float(step / conf.train.min_step), |
loss_s.item(), loss_nc.item(), loss_ent.item())) |
if step > 0 and step % conf.test.test_interval == 0: |
test(step, dataset_test, filename, n_share, num_class, G, C1, |
conf.train.thr) |
G.train() |
C1.train() |
train() |
# <FILESEP> |
import os |
import socket |
import argparse |
import threading |
from colorama import init, Fore, Style |
init(autoreset=True) |
class ChatClient: |
def __init__(self, host, port): |
self.host = host |
self.port = port |
self.client_socket = None |
self.username = None |
self.message_lock = threading.Lock() |
def connect(self): |
try: |
self.client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
self.client_socket.connect((self.host, self.port)) |
except ConnectionRefusedError as e: |
if e.errno == 111: |
print("Connection refused") |
else: |
print(f"An unknown error occurred {e}") |
return False |
return True |
def get_username(self): |
username_prompt = self.client_socket.recv(1024).decode('utf-8') |
print(Fore.CYAN + username_prompt, end="") |
username = input() |
self.client_socket.send(username.encode('utf-8')) |
response = self.client_socket.recv(1024).decode('utf-8') |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.