Skip to content

Instantly share code, notes, and snippets.

View sachinkale's full-sized avatar

Sachin Kale sachinkale

  • Working as Consultant
  • Toronto
View GitHub Profile
@sachinkale
sachinkale / createTFfromIAM.py
Created March 21, 2024 17:50
Python Script to create terraform files from existing roles in IAM
import json
import subprocess
import os
# Base directory where Terraform configurations will be saved
base_output_dir = 'terraform_roles_policies'
#policies_dir = os.path.join(base_output_dir, 'policies')
# Create directories if they don't exist
#os.makedirs(policies_dir, exist_ok=True)
from tensorflow.keras.models import load_model
import tensorflow as tf
from tensorflow.keras.preprocessing import image
from tensorflow.keras.applications.vgg16 import preprocess_input, decode_predictions
import numpy as np
import json
model = load_model('vggK5-weights-best.h5')
@sachinkale
sachinkale / vggKingfisher.py
Last active September 22, 2020 19:23
VGG16 transfer learning
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import os
from PIL import Image
import re
import json
$ python3 vgg.py
Found 758 images belonging to 19 classes.
Found 180 images belonging to 19 classes.
2020-09-17 14:42:07.878829: I tensorflow/core/platform/cpu_feature_guard.cc:143] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2020-09-17 14:42:07.901823: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x7fbe0c406470 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-09-17 14:42:07.901927: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): Host, Default Version
Model: "model"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
@sachinkale
sachinkale / visualize.py
Created September 9, 2020 16:30
Visualizing training result
acc = history.history['accuracy']
val_acc = history.history['val_accuracy']
loss=history.history['loss']
val_loss=history.history['val_loss']
epochs_range = range(epochs)
plt.figure(figsize=(8, 8))
plt.subplot(1, 2, 1)
@sachinkale
sachinkale / compile.py
Created September 9, 2020 16:28
Model Compilation
model.compile(optimizer = 'adam', loss = 'categorical_crossentropy', metrics = ['accuracy'])
model.summary()
history = model.fit(
x = training_set,
epochs=epochs,
validation_data=test_set
)
model = Sequential()
model.add(Conv2D(32, kernel_size=(3, 3), activation=tf.keras.layers.LeakyReLU(alpha=0.3), input_shape=(IMG_HEIGHT,IMG_WIDTH , 3)))
model.add(Conv2D(32, (3, 3), activation=tf.keras.layers.LeakyReLU(alpha=0.3)))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))
model.add(Conv2D(64, kernel_size=(3, 3), activation=tf.keras.layers.LeakyReLU(alpha=0.3)))
model.add(Conv2D(64, (3, 3), activation=tf.keras.layers.LeakyReLU(alpha=0.3)))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))
from tensorflow.keras.layers import Dense, Conv2D, Flatten, Dropout, MaxPooling2D
from tensorflow.keras.preprocessing.image import ImageDataGenerator
import tensorflow as tf
import os
import numpy as np
import matplotlib.pyplot as plt
batch_size = 24
epochs = 200
IMG_HEIGHT = 150
@sachinkale
sachinkale / resnet50.py
Created September 8, 2020 18:11
Detect object using ResNet50
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
model = ResNet50(weights='imagenet')
img_path = 'boris-smokrovic-Ori_JWlqVpc-unsplash.jpg'
img = image.load_img(img_path, target_size=(224, 224))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)
@sachinkale
sachinkale / yolo.py
Last active September 22, 2020 19:04
Extract Image from bounded box using YOLO
# import the necessary packages
from os import walk
import numpy as np
import argparse
import time
import cv2
import os
import re
# construct the argument parse and parse the arguments