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
#Train model and get metrics. | |
model.compile( | |
optimizer='adam', | |
loss='binary_crossentropy', | |
metrics=['accuracy'], | |
) | |
from keras.callbacks import Callback | |
class Histories(Callback): |
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
from dataclasses import dataclass, field | |
import numpy as np | |
from scipy.fft import fftshift, fft2, ifftshift, fft | |
from scipy.linalg import toeplitz | |
import matplotlib.pyplot as plt | |
@dataclass(repr=False) | |
class Bispectrum2D: | |
''' | |
Make Bispectrum dataclass from 1D signal with frequency in Hertz. |
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
from keras.applications.vgg16 import VGG16 | |
#Create dataset. The file_paths method shows train_ds and val_ds are mutually exclusive. | |
train_ds = tf.keras.utils.image_dataset_from_directory( | |
'./images/train/', | |
labels='inferred', | |
shuffle=True, | |
seed=8, | |
image_size=(224, 224), | |
batch_size=32) |
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
# Load and freeze VGG16 model. | |
# Include_top=False removes classification layer trained on ImageNet. | |
base_model = VGG16(weights="imagenet", include_top=False, input_shape=(224,224,3)) | |
base_model.trainable = False ## Not trainable weights | |
base_model.summary() |
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
#Load test dataset for evaluation. | |
test_ds = tf.keras.utils.image_dataset_from_directory( | |
'./images/test', | |
labels='inferred', | |
seed=None, | |
image_size=(224, 224), | |
batch_size=32) | |
model.evaluate(test_ds) |
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 crop_imag(imageFilePath: str, shakerange=20, shake_on=None): | |
'''Crop 1100x1100 images to 224X224. Optionally shake from center-crop | |
location (438,438,662,662). Return 224X224 image.''' | |
from PIL import Image | |
im = Image.open(imageFilePath) | |
rix = random.randint(-shakerange, shakerange) #get random int for x1, x2 | |
riy = random.randint(-shakerange, shakerange) #get random int for y1, y2 | |
if shake_on == True: | |
shaken_centercrop = (438+rix, 438+riy, 662+rix, 662+riy) | |
imCropped = im.crop(shaken_centercrop) #im.crop(x1, y1, x2, y2) - (x1,y1) top-left coord; (x2,y2) bottom-right coord |
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
#! /usr/bin/env python3 | |
# ~*~ utf-8 ~*~ | |
import mailbox | |
import bs4 | |
def get_html_text(html): | |
try: | |
return bs4.BeautifulSoup(html, 'lxml').body.get_text(' ', strip=True) | |
except AttributeError: # message contents empty |
OlderNewer