Skip to content

Instantly share code, notes, and snippets.

View pyaf's full-sized avatar
😎
learning everyday

Rishabh Agrahari pyaf

😎
learning everyday
View GitHub Profile
@pyaf
pyaf / UNet3D_without_BN.prototxt
Last active February 28, 2018 06:45
Visualizing 3D UNet (without BN layers)
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
@pyaf
pyaf / loss.py
Last active February 2, 2018 16:11
Loss function for MURA model
# 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__()
@pyaf
pyaf / datapipeline.py
Created February 2, 2018 15:22
Data pipeline and data augmentation on MURA dataset
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
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)
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',
...
)
class LoginForm(forms.Form):
username = forms.CharField()
password = forms.CharField()
class Meta:
fields = ['username','password']
def clean(self):
username = self.cleaned_data.get('username')
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')
@pyaf
pyaf / views.py
Last active March 24, 2017 11:22
PhoneVerificationView
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)
@pyaf
pyaf / authy.py
Created March 15, 2017 15:15
Authy API functions
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,
}
@pyaf
pyaf / views.py
Last active March 24, 2017 11:12
RegisterView
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']