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 getKeyPts(imgpath): | |
import cv2 | |
import mediapipe #uses RGB | |
import time | |
modelPose = mediapipe.solutions.pose | |
mpDraw = mediapipe.solutions.drawing_utils | |
pose = modelPose.Pose() | |
mp_holistic = mediapipe.solutions.holistic | |
#visit media pipe for landmark labels |
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 get_predictions(n): | |
image1= validgen[0][0][n] | |
plt.imshow(image1) | |
input_arr = ks.preprocessing.image.img_to_array(validgen[0][0][n]) | |
input_arr = np.array([input_arr]) # Convert single image to a batch. | |
predictions = model_com01[0].predict_classes(input_arr) | |
return predictions |
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 compiler2(model,train_generator,valid_generator,epchs,bsize=32,lr=0.0001): | |
from tensorflow import keras as ks | |
callbck = ks.callbacks.EarlyStopping(monitor='val_loss',patience=10, | |
verbose=2, | |
restore_best_weights=True,) | |
opt = ks.optimizers.Adam(learning_rate=lr) | |
model.compile(loss="categorical_crossentropy", |
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 imageclf2(input_shape): | |
from tensorflow import keras as ks | |
#from tensorflow.keras import regularizers | |
model = ks.models.Sequential() | |
#building architecture | |
#Adding layers | |
model.add(ks.layers.Conv2D(8,(3,3), | |
strides=1, | |
activation="relu", | |
padding='same', |
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
#Function that can build a dataframe on passing folderpath. | |
def getdata(folder_path): | |
sig = pd.DataFrame(columns=['image_abs_path','image_labels']) | |
for key,value in labelnames.items(): | |
#print("processing for label: {}".format(label)) | |
label_i = folder_path+"/"+str(key) | |
#read directory | |
dirs_label_i = os.listdir(label_i) | |
idx = 0 | |
for image in dirs_label_i: |
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 datapreprocessing(main_dir,bsize): | |
from tensorflow.keras.preprocessing.image import ImageDataGenerator | |
train_gen = ImageDataGenerator(rescale=1.0/255, | |
zoom_range=0.2, | |
shear_range=0.1, | |
horizontal_flip=True, | |
vertical_flip=True, | |
rotation_range=20, | |
width_shift_range=0.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
def get_predictions(n): | |
image1= validgen[0][0][n] | |
#print(image1.shape) | |
plt.imshow(image1) | |
input_arr = tf.keras.preprocessing.image.img_to_array(validgen[0][0][n]) | |
input_arr = np.array([input_arr]) # Convert single image to a batch. | |
predictions = model01[0].predict_classes(input_arr) | |
#our dictionary starts from 1 whereas model has classes from 0. | |
return insect_names[str(predictions[0]+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
def compiler(model,train_generator,valid_generator,epchs,bsize,lr=0.0001): | |
from tensorflow import keras as ks | |
callbck = ks.callbacks.EarlyStopping(monitor='val_loss',patience=20, | |
verbose=2,restore_best_weights=True) | |
#red_lr= ReduceLROnPlateau(monitor='val_acc',patience=3,verbose=1,factor=0.1) | |
opt = ks.optimizers.Adam(learning_rate=lr) | |
model.compile(loss="categorical_crossentropy", | |
optimizer=opt, |
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 insectclf(input_shape): | |
from tensorflow import keras as ks | |
#from tensorflow.keras import regularizers | |
model = ks.models.Sequential() | |
#building architecture | |
#Adding layers | |
model.add(ks.layers.Conv2D(16,(3,3), | |
strides=1, | |
activation="relu", | |
padding='valid', |
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 datapreprocessing(main_dir,bsize): | |
from tensorflow.keras.preprocessing.image import ImageDataGenerator | |
train_gen = ImageDataGenerator(rescale=1.0/255, | |
validation_split=0.30, | |
rotation_range=40, | |
horizontal_flip=True, | |
fill_mode='nearest') | |
train_generator = train_gen.flow_from_directory( |
NewerOlder