Skip to content

Instantly share code, notes, and snippets.

View CVxTz's full-sized avatar
💭
All Dawgz go to heaven

Mansar Youness CVxTz

💭
All Dawgz go to heaven
View GitHub Profile
@CVxTz
CVxTz / json_mode_gemini.py
Last active August 18, 2024 11:05
Json Mode using Gemini Flash
from dotenv import load_dotenv
import os
load_dotenv()
import google.generativeai as genai
from data_model import (
TouristLocation,
ClimateType,
ActivityType,
@CVxTz
CVxTz / query_unsplash.py
Created March 1, 2020 11:43
query unsplash
# First install https://github.com/yakupadakli/python-unsplash
# Unsplash API https://unsplash.com/documentation
import json
import os
from unsplash.api import Api
from unsplash.auth import Auth
with open('tokens.json', 'r') as f:
data = json.load(f)
def get_model(n_class=5):
inp = Input(shape=(187, 1))
x = Convolution1D(64, kernel_size=5, activation=activations.relu, padding="valid")(
inp
)
x = MaxPool1D(pool_size=4)(x)
x = Convolution1D(64, kernel_size=3, activation=activations.relu, padding="valid")(
x
)
x = MaxPool1D(pool_size=4)(x)
import numpy as np
def kl_loss(y_true, y_pred):
return np.sum(y_true * np.log(y_true / y_pred))
y_true = np.array([0.1, 0.5, 0.2, 0.15, 0.05])
y_pr_1 = np.array([0.15, 0.4, 0.2, 0.2, 0.05])
y_pr_2 = np.array([0.5, 0.1, 0.1, 0.2, 0.1])
for i, step_size in enumerate(step_sizes):
X_used = X[used_samples, ...]
Y_used = Y[used_samples, ...]
X_unused = X[unused_samples, ...]
Y_unused = Y[unused_samples, ...]
model = get_model()
for i, step_size in enumerate(step_sizes):
X_used = X[used_samples, ...]
Y_used = Y[used_samples, ...]
X_unused = X[unused_samples, ...]
Y_unused = Y[unused_samples, ...]
model = get_model()
X_used = X[used_samples, ...]
Y_used = Y[used_samples, ...]
X_unused = X[unused_samples, ...]
Y_unused = Y[unused_samples, ...]
model = get_model()
model.fit(X_used, Y_used, epochs=45, verbose=1, batch_size=32)
@CVxTz
CVxTz / gist:12fc23b6eb72b96a861ce0d99e0b1592
Last active February 1, 2020 16:03
First batch - Active Learning
step_sizes = [128]*20 # Succesive batch sizes
unused_samples = list(range(X.shape[0])) # Indexes of samples that were not used for training yet
step = np.random.choice(unused_samples, size=512).tolist() # First batch
used_samples = step # Indexes of samples that were used for training
unused_samples = list(set(unused_samples) - set(step))
def get_graph_embedding_model(n_nodes):
in_1 = Input((1,))
in_2 = Input((1,))
emb = Embedding(n_nodes, 100, name="node1")
x1 = emb(in_1)
x2 = emb(in_2)
x1 = Flatten()(x1)
x1 = Dropout(0.1)(x1)
x2 = Flatten()(x2)
x2 = Dropout(0.1)(x2)
def get_features_only_model(n_features, n_classes):
in_ = Input((n_features,))
x = Dense(10, activation="relu", kernel_regularizer=l1(0.001))(in_)
x = Dropout(0.5)(x)
x = Dense(n_classes, activation="softmax")(x)
model = Model(in_, x)
model.compile(loss="sparse_categorical_crossentropy", metrics=['acc'], optimizer="adam")