This file contains hidden or 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
import os | |
import math | |
import numpy as np | |
import json | |
from tensorflow import keras | |
from tensorflow.keras.metrics import categorical_accuracy | |
import tensorflow as tf | |
os.environ['TF_ENABLE_AUTO_MIXED_PRECISION'] = '1' | |
os.environ['TF_CPP_MIN_LOG_LEVEL']='2' |
This file contains hidden or 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
# building sample data generator | |
sample_generator = train_datagen.flow_from_directory(directory=TRAIN_DIR, | |
classes=['brightpixel', 'narrowband', | |
'narrowbanddrd', 'noise', | |
'squarepulsednarrowband', 'squiggle', | |
'squigglesquarepulsednarrowband'], | |
target_size=IMG_DIMS, | |
batch_size=1, | |
class_mode='categorical', | |
interpolation='bicubic', |
This file contains hidden or 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
# instantiating the image data generator objects | |
train_datagen = keras.preprocessing.image.ImageDataGenerator(rescale=1./255., | |
zoom_range=0.05, | |
rotation_range=180, | |
vertical_flip=True, | |
horizontal_flip=True, | |
fill_mode='reflect') | |
valid_datagen = keras.preprocessing.image.ImageDataGenerator(rescale=1./255.) | |
test_datagen = keras.preprocessing.image.ImageDataGenerator(rescale=1./255.) |
This file contains hidden or 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.preprocessing.image import img_to_array, load_img | |
import glob | |
import matplotlib.pyplot as plt | |
%matplotlib inline | |
data_signal_files = glob.glob(TRAIN_DIR+'/*/*.png') | |
sample_files = [data_signal_files[idx] for idx in range(0, 5600, 800+15)] | |
fix, ax = plt.subplots(2, 4, figsize=(14, 6)) | |
for idx, img in enumerate(sample_files): |
This file contains hidden or 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
fig, ax = plt.subplots(2, 4, figsize=(14, 6)) | |
for idx, img in enumerate(sample_files): | |
id1 = 1 if idx > 3 else 0 | |
id2 = idx % 4 | |
img_arr = img_to_array(load_img(img)) | |
f = ax[id1, id2].imshow(img_arr / 255., aspect='auto') | |
t = ax[id1, id2].set_title(img.split('/')[-1].split('.')[0].split('_')[-1], fontsize=10) | |
ax[1,3].set_axis_off() |
This file contains hidden or 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
import cv2 | |
img_arr_bgr = cv2.imread(sample_files[2]) | |
img_arr_rgb = cv2.cvtColor(img_arr_bgr, cv2.COLOR_BGR2RGB) | |
print('Image Shape:', img_arr.shape) | |
fig, ax = plt.subplots(1, 2, figsize=(10, 4)) | |
p1 = ax[0].imshow(img_arr_bgr, aspect='auto') | |
t1 = ax[0].set_title('BGR spectrogram') | |
p2 = ax[1].imshow(img_arr_rgb, aspect='auto') | |
t1 = ax[1].set_title('RGB spectrogram') |
This file contains hidden or 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.preprocessing.image import img_to_array, load_img | |
img = load_img(sample_files[2]) | |
img_arr = img_to_array(img) | |
print('Image Shape:', img_arr.shape) | |
fig, ax = plt.subplots(1, 2, figsize=(10, 4)) | |
p1 = ax[0].imshow(np.array(img_arr, dtype='uint8'), aspect='auto') | |
t1 = ax[0].set_title('Image Spectrogram') | |
p2 = ax[1].imshow(img_arr / 255., aspect='auto') | |
t2 = ax[1].set_title('Image Spectrogram Normalized (0-1)') |
This file contains hidden or 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_dir = os.path.join('./data/train') | |
data_signal_files = glob.glob(train_dir+'/*/*.png') | |
sample_files = [data_signal_files[idx] for idx in range(0, 5600, 800+10)] | |
sample_files | |
# Output | |
['./data/train/brightpixel/272_brightpixel.png', | |
'./data/train/squigglesquarepulsednarrowband/6438_squigglesquarepulsednarrowband.png', | |
'./data/train/narrowbanddrd/2012_narrowbanddrd.png', | |
'./data/train/squarepulsednarrowband/1396_squarepulsednarrowband.png', |
This file contains hidden or 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
!sudo tree --dirsfirst --filelimit 10 './data/' | |
./data/ | |
├── test | |
│ ├── brightpixel [100 entries exceeds filelimit, not opening dir] | |
│ ├── narrowband [100 entries exceeds filelimit, not opening dir] | |
│ ├── narrowbanddrd [100 entries exceeds filelimit, not opening dir] | |
│ ├── noise [100 entries exceeds filelimit, not opening dir] | |
│ ├── squarepulsednarrowband [100 entries exceeds filelimit, not opening dir] | |
│ ├── squiggle [100 entries exceeds filelimit, not opening dir] |
This file contains hidden or 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
fig, ax = plt.subplots(4, 4, figsize=(12, 10)) | |
id1 = 0 | |
id2 = 0 | |
for signal_type in df['signal_classification'].unique().tolist(): | |
data_ids = df[df['signal_classification']==signal_type].sample(n=2)['uuid'].tolist() | |
data_files = [f for f in raw_signal_files if [x for x in data_ids if x in f]] | |
for idx, data_file in enumerate(data_files): | |
data = ibmseti.compamp.SimCompamp(open(data_file,'rb').read()) | |
spectrogram = data.get_spectrogram() |