Skip to content

Instantly share code, notes, and snippets.

View hsleonis's full-sized avatar
🏝️
Travellers unite.

Hasan Shahriar hsleonis

🏝️
Travellers unite.
View GitHub Profile
@hsleonis
hsleonis / tuple_append.py
Created December 14, 2022 00:22
Append to tuple in Python
# Creating a Tuple
a_tuple = (1, 2, 3)
# Method 1: Tuple Concatenation
a_tuple = a_tuple + (4,)
print(a_tuple)
# Returns: (1, 2, 3, 4) <- an entirely new object
# Method 2: List Conversion
@hsleonis
hsleonis / multiprocessor.py
Created December 10, 2022 23:49
Multiprocessor Pool API
from multiprocessor import Pool
# multiprocessor.Pool API allows to distribute workload over several processes
# Function to apply a function over multiple cores
@print_timing
def parallel_apply(apply_func, groups, nb_cores):
with Pool(nb_cores) as p:
results = p.map(apply_func, groups)
return pd.concat(results)
@hsleonis
hsleonis / number_encoder.py
Created November 21, 2022 11:25
Encode and Decode numbers
def encode(num: int):
digits = str(num)
out = 0
prev = 0
for tmp in digits:
tmp = 10 if tmp=='0' else int(tmp)
cur_prev = prev
prev = tmp
@hsleonis
hsleonis / resnet.py
Created December 8, 2021 20:36
ResNet Neural Network
from tensorflow.keras.applications.resnet50 import ResNet50
from tensorflow.keras.preprocessing import image
from tensorflow.keras.applications.resnet50 import preprocess_input, decode_predictions
import numpy as np
# image
img_path = 'elephant.jpg'
img = image.load_img(img_path, target_size=(224, 224))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
@hsleonis
hsleonis / vgg.py
Last active December 8, 2021 20:32
VGG Neural Network
from tensorflow.keras.applications.vgg16 import VGG16
from tensorflow.keras.applications.vgg19 import VGG19
from tensorflow.keras.preprocessing import image
from tensorflow.keras.applications.vgg16 import preprocess_input
import numpy as np
# image
img_path = 'elephant.jpg'
img = image.load_img(img_path, target_size=(224, 224))
x = image.img_to_array(img)
@hsleonis
hsleonis / Inception_v3.py
Created December 8, 2021 19:42
Inception v3 Neural Network
## Fine-tune InceptionV3 on a new set of classes
from tensorflow.keras.applications.inception_v3 import InceptionV3
from tensorflow.keras.preprocessing import image
from tensorflow.keras.models import Model
from tensorflow.keras.layers import Dense, GlobalAveragePooling2D
# create the base pre-trained model
base_model = InceptionV3(weights='imagenet', include_top=False)
@hsleonis
hsleonis / alexnet.py
Created December 8, 2021 16:44
ALexNet - Deep Neural Network
# -*- coding: utf-8 -*-
"""
AlexNet
"""
import tensorflow as tf
import numpy as np
from tensorflow.keras.layers import Activation, Conv2D, AveragePooling2D, Dense, Flatten, BatchNormalization, MaxPool2D, Dropout
from tensorflow.keras.models import Sequential
from tensorflow.keras.datasets import mnist
@hsleonis
hsleonis / lenet.py
Created December 8, 2021 00:51
LeNet - Deep Learning Neural Network
# -*- coding: utf-8 -*-
"""
LeNet - Deep Learning Neural Network
"""
import tensorflow as tf
import numpy as np
from tensorflow.keras.layers import Conv2D, AveragePooling2D, Dense, Flatten
from tensorflow.keras.models import Sequential
from tensorflow.keras.datasets import mnist
@hsleonis
hsleonis / cuda_version.py
Created November 30, 2021 10:39
Get CUDA Version
import tensorflow as tf
from tensorflow.python.platform import build_info as build
print(f"tensorflow version: {tf.__version__}")
print(f"Cuda Version: {build.build_info['cuda_version']}")
print(f"Cudnn version: {build.build_info['cudnn_version']}")
@hsleonis
hsleonis / jquery.modal.js
Created October 26, 2020 18:05
Shopify newsletter popup
/*
A simple jQuery modal (http://github.com/kylefox/jquery-modal)
Version 0.9.1
*/
!function(o){"object"==typeof module&&"object"==typeof module.exports?o(require("jquery"),window,document):o(jQuery,window,document)}(function(o,t,i,e){var s=[],l=function(){return s.length?s[s.length-1]:null},n=function(){var o,t=!1;for(o=s.length-1;o>=0;o--)s[o].$blocker&&(s[o].$blocker.toggleClass("current",!t).toggleClass("behind",t),t=!0)};o.modal=function(t,i){var e,n;if(this.$body=o("body"),this.options=o.extend({},o.modal.defaults,i),this.options.doFade=!isNaN(parseInt(this.options.fadeDuration,10)),this.$blocker=null,this.options.closeExisting)for(;o.modal.isActive();)o.modal.close();if(s.push(this),t.is("a"))if(n=t.attr("href"),this.anchor=t,/^#/.test(n)){if(this.$elm=o(n),1!==this.$elm.length)return null;this.$body.append(this.$elm),this.open()}else this.$elm=o("<div>"),this.$body.append(this.$elm),e=function(o,t){t.elm.remove()},this.showSpinner(),t.trigger(o.modal.AJAX_SEND),o.get(n).done(function(i){if(o.m