-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmove_and_label_science_bowl.py
73 lines (47 loc) · 4.28 KB
/
move_and_label_science_bowl.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
import numpy as np
#Import libraries for doing image analysis
from skimage.io import imread
from skimage.transform import resize
from sklearn.ensemble import RandomForestClassifier as RF
import glob
import sklearn
import os
from sklearn import cross_validation
from sklearn.cross_validation import StratifiedKFold as KFold
from sklearn.metrics import classification_report
from matplotlib import pyplot as plt
from matplotlib import colors
from pylab import cm
from skimage import segmentation
from skimage.morphology import watershed
from skimage import measure
from skimage import morphology
import numpy as np
import pandas as pd
from scipy import ndimage
from skimage.feature import peak_local_max
import h5py
import shutil
import random
root = '/home/ecater/Desktop/caffe/data/science_bowl/train'
val_root = '/home/ecater/Desktop/caffe/data/science_bowl/val'
y = """acantharia_protist_big_center acantharia_protist_halo acantharia_protist amphipods appendicularian_fritillaridae appendicularian_s_shape appendicularian_slight_curve appendicularian_straight artifacts_edge artifacts chaetognath_non_sagitta chaetognath_other chaetognath_sagitta chordate_type1 copepod_calanoid_eggs copepod_calanoid_eucalanus copepod_calanoid_flatheads copepod_calanoid_frillyAntennae copepod_calanoid_large_side_antennatucked copepod_calanoid_large copepod_calanoid_octomoms copepod_calanoid_small_longantennae copepod_calanoid copepod_cyclopoid_copilia copepod_cyclopoid_oithona_eggs copepod_cyclopoid_oithona copepod_other crustacean_other ctenophore_cestid ctenophore_cydippid_no_tentacles ctenophore_cydippid_tentacles ctenophore_lobate decapods detritus_blob detritus_filamentous detritus_other diatom_chain_string diatom_chain_tube echinoderm_larva_pluteus_brittlestar echinoderm_larva_pluteus_early echinoderm_larva_pluteus_typeC echinoderm_larva_pluteus_urchin echinoderm_larva_seastar_bipinnaria echinoderm_larva_seastar_brachiolaria echinoderm_seacucumber_auricularia_larva echinopluteus ephyra euphausiids_young euphausiids fecal_pellet fish_larvae_deep_body fish_larvae_leptocephali fish_larvae_medium_body fish_larvae_myctophids fish_larvae_thin_body fish_larvae_very_thin_body heteropod hydromedusae_aglaura hydromedusae_bell_and_tentacles hydromedusae_h15 hydromedusae_haliscera_small_sideview hydromedusae_haliscera hydromedusae_liriope hydromedusae_narco_dark hydromedusae_narco_young hydromedusae_narcomedusae hydromedusae_other hydromedusae_partial_dark hydromedusae_shapeA_sideview_small hydromedusae_shapeA hydromedusae_shapeB hydromedusae_sideview_big hydromedusae_solmaris hydromedusae_solmundella hydromedusae_typeD_bell_and_tentacles hydromedusae_typeD hydromedusae_typeE hydromedusae_typeF invertebrate_larvae_other_A invertebrate_larvae_other_B jellies_tentacles polychaete protist_dark_center protist_fuzzy_olive protist_noctiluca protist_other protist_star pteropod_butterfly pteropod_theco_dev_seq pteropod_triangle radiolarian_chain radiolarian_colony shrimp_caridean shrimp_sergestidae shrimp_zoea shrimp-like_other siphonophore_calycophoran_abylidae siphonophore_calycophoran_rocketship_adult siphonophore_calycophoran_rocketship_young siphonophore_calycophoran_sphaeronectes_stem siphonophore_calycophoran_sphaeronectes_young siphonophore_calycophoran_sphaeronectes siphonophore_other_parts siphonophore_partial siphonophore_physonect_young siphonophore_physonect stomatopod tornaria_acorn_worm_larvae trichodesmium_bowtie trichodesmium_multiple trichodesmium_puff trichodesmium_tuft trochophore_larvae tunicate_doliolid_nurse tunicate_doliolid tunicate_partial tunicate_salp_chains tunicate_salp unknown_blobs_and_smudges unknown_sticks unknown_unclassified """
folders = y.split()
numberofImages = 0
images_to_move = 0
train_txt = open("train.txt", "a")
test_txt = open("test.txt", "a")
for i in range(len(folders)):
for fileNameDir in os.walk(root + '/' + folders[i]):
for fileName in fileNameDir[2]:
if fileName[-4:] != ".jpg":
continue
chance = random.randint(1, 100)
if chance <= 10:
shutil.move(root + '/' + folders[i] + '/' + fileName, val_root)
test_txt.write(fileName + " " + str(i) + '\n')
images_to_move +=1
else:
train_txt.write(folders[i] + '/' + fileName + " " + str(i) + '\n')
numberofImages += 1
print numberofImages, images_to_move