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
import json | |
import os | |
import numpy as np | |
import pandas as pd | |
import tensorflow as tf | |
from keras import backend as K | |
from keras.models import load_model | |
from rest_framework.decorators import api_view |
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 _load_model_from_path(path): | |
global gGraph | |
global gModel | |
gGraph = tf.get_default_graph() | |
gModel = load_model(path) # keras function | |
_load_model_from_path('path_to_model') |
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
################################################### | |
# settings.py/the file where to load the models | |
################################################### | |
def load_model_from_path(path): | |
graph = tf.get_default_graph() | |
model = load_model(path) | |
return graph, model | |
def load_all_models(): | |
global gModelObjs # each object is a tuple of graph, model |
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 fibonacci_sequence(n): | |
curr_val = 0 | |
next_val = 1 | |
for i in range(n): | |
yield curr_val | |
curr_val, next_val = next_val, curr_val + next_val | |
if __name__ == '__main__': | |
fib_seq = [] | |
for fn in fibonacci_sequence(10): |
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 multiplier(n): | |
step = None | |
result = 1 | |
for i in range(1, n+1): | |
if step is None: | |
step = 1 | |
result *= (i*step) | |
print(f"i:{i}, step={step}") | |
step = yield result |
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 my_gen_1(n): | |
for i in range(n): | |
yield f'g1: {i}' | |
def my_gen_2(n): | |
for j in range(n): | |
yield f'g2: {-j}' | |
def my_gen_master(n): | |
yield from my_gen_1(n) |
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 fib(n): | |
if n == 0: | |
return 0 | |
if n == 1: | |
return 1 | |
fn_2 = 0 | |
fn_1 = 1 | |
for i in range(n-1): |
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
# recursion | |
def fib(n): | |
if n==0: | |
return 0 | |
if n==1: | |
return 1 | |
return fib(n-1) + fib(n-2) |
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
# DP | |
fib_seq = [0, 1] | |
def fib(n): | |
if n == 0: | |
return 0 | |
if n == 1: | |
return 1 | |
if len(fib_seq) == n-1: |
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 Example: | |
@classmethod | |
def foo(cls, arg1, arg2, ...): | |
pass |
OlderNewer