This file contains hidden or 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
# [cat, dog] | |
def label_image(img): | |
label = img.split('.')[-3] | |
if label == 'cat': | |
return [1,0] | |
else: | |
return [0,1] | |
# Here we generate train data with fixed size and we save it | |
def create_train_data(): |
This file contains hidden or 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
import cv2 | |
import numpy as np | |
import os | |
from random import shuffle | |
from tqdm import tqdm | |
TRAIN_DIR = '/home/yerkebulan/app/dev/projects/classification_research/dogs-vs-cats/train' | |
TEST_DIR = '/home/yerkebulan/app/dev/projects/classification_research/dogs-vs-cats/test1' | |
IMG_SIZE = 50 | |
LR = 1e-3 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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.contrib import admin | |
from django.urls import path | |
from users.views import signin, user_info | |
urlpatterns = [ | |
path('admin/', admin.site.urls), | |
path('api/v1/signin', signin), | |
path('api/v1/user_info', user_info), |
This file contains hidden or 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
@api_view(["GET"]) | |
def user_info(request): | |
return Response({ | |
'user': request.user.username, | |
'expires_in': expires_in(request.auth) | |
}, status=HTTP_200_OK) |
This file contains hidden or 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
REST_FRAMEWORK = { | |
'DEFAULT_AUTHENTICATION_CLASSES': ( | |
'users.authentication.ExpiringTokenAuthentication', # custom authentication class | |
), | |
'DEFAULT_PERMISSION_CLASSES': ( | |
'rest_framework.permissions.IsAuthenticated', | |
) | |
} |
This file contains hidden or 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 rest_framework.authentication import TokenAuthentication | |
from rest_framework.authtoken.models import Token | |
from rest_framework.exceptions import AuthenticationFailed | |
from datetime import timedelta | |
from django.utils import timezone | |
from django.conf import settings | |
This file contains hidden or 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 rest_framework.authtoken.models import Token | |
from datetime import timedelta | |
from django.utils import timezone | |
from django.conf import settings | |
#this return left time | |
def expires_in(token): |
This file contains hidden or 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.contrib import admin | |
from django.urls import path | |
from users.views import signin | |
urlpatterns = [ | |
path('admin/', admin.site.urls), | |
path('api/v1/signin', signin) | |
] |
This file contains hidden or 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 rest_framework import serializers | |
class UserSigninSerializer(serializers.Serializer): | |
username = serializers.CharField(required = True) | |
password = serializers.CharField(required = True) |