This file contains 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
name: 'kidney_seg_no_BN' | |
force_backward: true | |
layer { top: 'data' top: 'label' top: 'weights' name: 'loaddata' type: 'HDF5Data' hdf5_data_param { source: 'trainfileList.txt' batch_size: 1 } include: { phase: TRAIN }} | |
layer { type: 'CreateDeformation' | |
top: 'def' | |
name: 'create_deformation' | |
create_deformation_param { | |
random_offset_range_from_ignore_label: 0 | |
batch_size: 1 nz: 116 ny: 132 nx: 132 ncomponents: 3 |
This file contains 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
# tai = total abnormal images, tni = total normal images | |
# study_data[x] is a study level dataframe | |
tai = {x: get_count(study_data[x], 'positive') for x in data_cat} | |
tni = {x: get_count(study_data[x], 'negative') for x in data_cat} | |
Wt1 = {x: n_p(tni[x] / (tni[x] + tai[x])) for x in data_cat} | |
Wt0 = {x: n_p(tai[x] / (tni[x] + tai[x])) for x in data_cat} | |
class Loss(torch.nn.modules.Module): | |
def __init__(self, Wt1, Wt0): | |
super(Loss, self).__init__() |
This file contains 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
data_cat = ['train', 'valid'] # data categories | |
class ImageDataset(Dataset): | |
"""training dataset.""" | |
def __init__(self, df, transform=None): | |
""" | |
Args: | |
df (pd.DataFrame): a pandas DataFrame with image path and labels. | |
transform (callable, optional): Optional transform to be applied |
This file contains 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 save_profile(sender, instance, **kwargs): | |
print(instance) | |
instance.user.full_name = instance.extra_data['name'] | |
uid = instance.extra_data['id'] | |
instance.user.profile_picture = instance.get_avatar_url() | |
instance.user.save() | |
post_save.connect(save_profile, sender=SocialAccount) |
This file contains 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
AUTHENTICATION_BACKENDS = ( | |
... | |
# Needed to login by username in Django admin, regardless of `allauth` | |
'django.contrib.auth.backends.ModelBackend', | |
# `allauth` specific authentication methods, such as login by e-mail | |
'allauth.account.auth_backends.AuthenticationBackend', | |
... | |
) |
This file contains 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 LoginForm(forms.Form): | |
username = forms.CharField() | |
password = forms.CharField() | |
class Meta: | |
fields = ['username','password'] | |
def clean(self): | |
username = self.cleaned_data.get('username') |
This file contains 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 LoginView(FormView): | |
template_name = 'login.html' | |
form_class = LoginForm | |
success_url = '/dashboard' | |
def dispatch(self, request, *args, **kwargs): | |
if self.request.user.is_authenticated: | |
messages.add_message(self.request, messages.INFO, | |
"User already logged in") | |
return redirect('/dashboard') |
This file contains 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 PhoneVerificationView(request, **kwargs): | |
template_name = 'phone_confirm.html' | |
if request.method == "POST": | |
username = request.POST['username'] | |
user = User.objects.get(username=username) | |
form = PhoneVerificationForm(request.POST) | |
if form.is_valid(): | |
verification_code = request.POST['one_time_password'] | |
response = verify_sent_code(verification_code, user) |
This file contains 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
from django.conf import settings | |
import requests | |
def send_verfication_code(user): | |
data = { | |
'api_key': settings.AUTHY_KEY, | |
'via': 'sms', | |
'country_code': user.country_code, | |
'phone_number': user.phone_number, | |
} |
This file contains 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 RegisterView(SuccessMessageMixin, FormView): | |
template_name = 'register.html' | |
form_class = RegisterForm | |
success_message = "One-Time password sent to your registered mobile number.\ | |
The verification code is valid for 10 minutes." | |
def form_valid(self, form): | |
user = form.save() | |
username = self.request.POST['username'] | |
password = self.request.POST['password1'] |