Skip to content

Instantly share code, notes, and snippets.

View trongan93's full-sized avatar

Trong-An (Andrew) Bui trongan93

View GitHub Profile
# Reference from **Bidimensional Empirical Mode Decomposition** code by Dawid Laszuk (laszukdawid@gmail.com).
# This version is modified by H-BEMD for sin and cos value and optimize Extrema detection and Normolization value
# By Trong-An Bui (trongan93@gmail.com - http://buitrongan.com)
class BEMD:
def __init__(self):
# ProtoIMF related
self.mse_thr = 0.01
self.mean_thr = 0.01
self.FIXE = 1 # Single iteration by default, otherwise results are terrible
bgrInputImage = cv2.imread(img_path)
bgrInputImage = cv2.resize(bgrInputImage,(224,224))
rgb_resized_img = cv2.cvtColor(bgrInputImage,cv2.COLOR_BGR2RGB)
hsvInputImage_Full = cv2.cvtColor(rgb_resized_img.astype(np.float32), cv2.COLOR_RGB2HSV_FULL)
hue_full, sat_full, val_full = cv2.split(hsvInputImage_Full)
hue_16bit = np.array(hue_full,dtype=np.uint16)
for e in coordinates:
show_ship(e[0][0], e[0][1], e[1][0][1])
picture_tensor = picture_tensor.transpose(1,2,0)
picture_tensor.shape
plt.figure(1, figsize = (15, 30))
plt.subplot(3,1,1)
plt.imshow(picture_tensor)
step = 10; coordinates = []
for y in range(int((height-(80-step))/step)):
for x in range(int((width-(80-step))/step) ):
area = cutting(x*step, y*step)
result = model.predict(area)
if result[0][1] > 0.90 and not_near(x*step,y*step, 88, coordinates):
coordinates.append([[x*step, y*step], result])
print(result)
plt.imshow(area[0])
plt.show()
def cutting(x, y):
area_study = np.arange(3*80*80).reshape(3, 80, 80)
for i in range(80):
for j in range(80):
area_study[0][i][j] = picture_tensor[0][y+i][x+j]
area_study[1][i][j] = picture_tensor[1][y+i][x+j]
area_study[2][i][j] = picture_tensor[2][y+i][x+j]
area_study = area_study.reshape([-1, 3, 80, 80])
area_study = area_study.transpose([0,2,3,1])
area_study = area_study / 255
image = Image.open('./ships-in-satellite-imagery/scenes/scenes/sfbay_1.png')
pix = image.load()
n_spectrum = 3
width = image.size[0]
height = image.size[1]
# creat vector
picture_vector = []
for chanel in range(n_spectrum):
# optimization setup
sgd = SGD(lr=0.01, momentum=0.9, nesterov=True)
model.compile(
loss='categorical_crossentropy',
optimizer=sgd,
metrics=['accuracy'])
# training
model.fit(
X_train,
model = Sequential()
model.add(Conv2D(32, (3, 3), padding='same', input_shape=(80, 80, 3), activation='relu'))
model.add(MaxPooling2D(pool_size=(2, 2))) #40x40
model.add(Dropout(0.25))
model.add(Conv2D(32, (3, 3), padding='same', activation='relu'))
model.add(MaxPooling2D(pool_size=(2, 2))) #20x20
model.add(Dropout(0.25))
physical_devices = tf.config.experimental.list_physical_devices('GPU')
for physical_device in physical_devices:
tf.config.experimental.set_memory_growth(physical_device, True)
@trongan93
trongan93 / ship_detection_preparedata
Created June 12, 2020 08:41
ship_detection_preparedata
# output encoding
y = tensorflow.keras.utils.to_categorical(output_data, 2)
# shuffle all indexes
indexes = np.arange(2800)
np.random.shuffle(indexes)
X_train = X[indexes].transpose([0,2,3,1])
y_train = y[indexes]