(still a work-in-progress)
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
# set temporary IP | |
ip a | |
sudo ip addr add <ipv4_addr>/<netmask> dev <interface> | |
sudo ip route add default via <gateway_ip> | |
# set temporary DNS | |
sudo nano /etc/resolv.conf | |
# nameserver 8.8.8.8 | |
# set permanent IP |
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
# Clear variable | |
cnn_model = None | |
# Call a create model function | |
cnn_model = create_model(image_shape=(256, 4096, 1)) | |
# Declare the a callback function | |
# Early stopping callback | |
earlystopping = EarlyStopping(monitor='val_accuracy', patience=2) | |
# ModelCheckpoin callabck | |
filepath = project_path + "/model/weights_best.hdf5" | |
checkpoint = ModelCheckpoint(filepath, monitor='val_accuracy', verbose=1, save_best_only=True, mode='max') |
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
# set number of split | |
kfold_splits = 4 | |
# set number of epoch | |
n_epoch = 10 | |
# set batch size | |
batch_size = 10 | |
# create StratifiedKFold | |
skf = StratifiedKFold(n_splits=kfold_splits, shuffle=True) | |
for index, (train_indices, val_indices) in enumerate(skf.split(X, y)): |
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 tensorflow.keras import datasets, layers, models, optimizers, regularizers, callbacks | |
from tensorflow.keras.callbacks import EarlyStopping, ModelCheckpoint | |
def create_model(image_shape=(256, 4096, 1), print_summary=False): | |
# initial model | |
model = models.Sequential() | |
# CONV layer: filter 16, stride 7x7 | |
model.add(layers.Conv2D(16, (7, 7),input_shape=image_shape)) | |
# Batch Normalization layer -> avoid overfitting |
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
# We random by shuffling the order of defect-free and defect images | |
np.random.shuffle(non_defect_images) | |
np.random.shuffle(defect_images) | |
# The class size is the min length compared with defect-free and defect images | |
class_size = defect_images.shape[0] if defect_images.shape[0] <= non_defect_images.shape[0] else non_defect_images.shape[0] | |
# Declare dataset by concat defect_images and non_defect_images with length 0 to class_size | |
dataset = np.concatenate((defect_images[:class_size], non_defect_images[:class_size])) | |
# Create an empty matrix X with is matrix of 256x4096 and has dataset length row | |
X = np.empty([dataset.shape[0], 256, 4096]).astype(int) | |
# Create vector y which has dataset length |
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
defect_images_path = project_path + "/dataset/Defect_images" | |
non_defect_images_path1 = project_path + "/dataset/NoDefect_images/2306881-210020u" | |
non_defect_images_path2 = project_path + "/dataset/NoDefect_images/2306894-210033u" | |
non_defect_images_path3 = project_path + "/dataset/NoDefect_images/2311517-195063u" | |
non_defect_images_path4 = project_path + "/dataset/NoDefect_images/2311694-1930c7u" | |
non_defect_images_path5 = project_path + "/dataset/NoDefect_images/2311694-2040n7u" | |
non_defect_images_path6 = project_path + "/dataset/NoDefect_images/2311980-185026u" | |
non_defect_images_path7 = project_path + "/dataset/NoDefect_images/2608691-202020u" | |
mask_images_path = project_path + "/dataset/Mask_images" |
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
def load_file(file_path, label): | |
# declare the folder name | |
folder_name = file_path.split("/")[-1] | |
# declare output list | |
out_list = [] | |
# load every file that .png format | |
for image_path in glob.glob(file_path + "/*.png"): | |
# read image file | |
image = imageio.imread(image_path) | |
# declare temporary dict dtype |
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
# -*- coding: utf-8 -*- | |
""" | |
This script will delete all of the tweets in the specified account. | |
You may need to hit the "more" button on the bottom of your twitter profile | |
page every now and then as the script runs, this is due to a bug in twitter. | |
You will need to get a consumer key and consumer secret token to use this | |
script, you can do so by registering a twitter application at https://dev.twitter.com/apps | |
@requirements: Python 2.5+, Tweepy (http://pypi.python.org/pypi/tweepy/1.7.1) |