-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
70 lines (58 loc) · 1.65 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# import neccesary packages
import numpy as np
import pandas as pd
import tensorflow as tf
import keras.backend as K
from sklearn.model_selection import train_test_split
import matplotlib.pyplot as plt
import os
import cv2
dir0 = '....../train/images'
dir1 = '....../train/masks'
files = []
image_path = []
for dirname, _, filenames in os.walk(dir0):
for filename in filenames:
path = os.path.join(dirname, filename)
image_path.append(path)
file = filename.split(".")[0]
files.append(file)
d = {"id": files, "image_path": image_path}
df = pd.DataFrame(data = d)
df = df.set_index('id')
df
mfiles = []
mask_path = []
for dirname, _, filenames in os.walk(dir1):
for filename in filenames:
path = os.path.join(dirname, filename)
mask_path.append(path)
mfile = filename.split(".")[0]
# car_id = car_id.split("_mask")[0]
mfiles.append(mfile)
d = {"id": mfiles,"mask_path": mask_path}
mask_df = pd.DataFrame(data = d)
mask_df = mask_df.set_index('id')
mask_df
# read and plot image and corresponding mask
import cv2
path0='....../train/images/deforestation_2121.png'
img0=cv2.imread(path0,cv2.IMREAD_GRAYSCALE)
shape0=img0.shape
print(shape0)
plt.imshow(img0)
plt.show()
path1='......./train/masks/deforestation_2121.png'
img1=cv2.imread(path1,cv2.IMREAD_GRAYSCALE)
shape1=img1.shape
print(shape1)
plt.imshow(img1)
plt.show()
# combine dataframes of image and mask
df["mask_path"] = mask_df["mask_path"]
df
# set test data df
n = len(df)
print(n)
test_df = df.iloc[(n//10)*3:(n//10)*4]
#print(test_df)