Skip to content

Commit 025dee0

Browse files
committed
Updated dockerfile, geo_coords
1 parent e68546a commit 025dee0

File tree

7 files changed

+131
-93
lines changed

7 files changed

+131
-93
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ During the test phase, input images of arbitrary size are processed.
127127
--label_map_path class_labels_car.pbtxt \
128128
--train_model_path [ssd_train_path] \
129129
--tf_cfg_train_file ssd_inception_v2_simrdwn.config \
130-
--use_tfrecords=1 \
130+
--use_tfrecords=0 \
131131
--testims_dir cowc/Utah_AGRC \
132132
--keep_test_slices 0 \
133133
--test_slice_sep __ \
@@ -142,7 +142,7 @@ During the test phase, input images of arbitrary size are processed.
142142
143143
# YOLT vehicle search
144144
python /raid/local/src/simrdwn/core/simrdwn.py \
145-
--framework yolt \
145+
--framework yolt2 \
146146
--mode test \
147147
--outname dense_cowc \
148148
--label_map_path class_labels_car.pbtxt \

docker/Dockerfile

+74-53
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22
FROM nvidia/cuda:9.0-devel-ubuntu16.04
33
MAINTAINER avanetten
44

5-
# nvidia-docker build -t simrdwn2.1 . # build (use existing packages)
6-
# nvidia-docker build --no-cache -t simrdwn2.2 . # rebuild from scratch
7-
# NV_GPU=0 nvidia-docker run -it -v /local_data:/local_data --name simrdwn2.2_gpu0 simrdwn2.2
8-
# NV_GPU=0 nvidia-docker run -it -v /local_data:/local_data -v /cosmiq:/cosmiq --name simrdwn2.1_gpu0 simrdwn2.1
9-
105
# IF YOU WANT PROGRESS PRINTED TO TERMINAL
116
# Update model_main to log to screen...
127
# https://stackoverflow.com/questions/52016255/tensorflow-object-detection-api-not-displaying-global-steps
@@ -73,78 +68,84 @@ SHELL ["/bin/bash", "-c"]
7368
ENV PATH /opt/conda/bin:$PATH
7469

7570
# install anaconda
76-
RUN wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-4.5.4-Linux-x86_64.sh -O ~/miniconda.sh && \
71+
# https://repo.continuum.io/miniconda/
72+
RUN wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-4.6.14-Linux-x86_64.sh -O ~/miniconda.sh && \
7773
/bin/bash ~/miniconda.sh -b -p /opt/conda && \
7874
rm ~/miniconda.sh && \
7975
/opt/conda/bin/conda clean -tipsy && \
8076
ln -s /opt/conda/etc/profile.d/conda.sh /etc/profile.d/conda.sh && \
8177
echo ". /opt/conda/etc/profile.d/conda.sh" >> ~/.bashrc && \
8278
echo "conda activate base" >> ~/.bashrc
83-
ENV TINI_VERSION v0.16.1
79+
# ENV TINI_VERSION v0.16.1
80+
ENV TINI_VERSION v0.18.0
8481
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /usr/bin/tini
8582
RUN chmod +x /usr/bin/tini
8683

8784
# use conda-forge instead of default channel
88-
RUN conda update conda && \
89-
conda config --remove channels defaults && \
90-
conda config --add channels conda-forge
85+
RUN conda config --add channels conda-forge
86+
# && \
87+
# conda update conda
88+
# conda config --remove channels defaults && \
9189

9290
# set up conda environment and add to $PATH
93-
RUN conda create -n simrdwn2 python=3.6 \
94-
&& echo "source activate simrdwn2" > ~/.bashrc
95-
ENV PATH /opt/conda/envs/simrdwn2/bin:$PATH
91+
RUN conda create -n simrdwn python=3.6 \
92+
&& echo "source activate simrdwn" > ~/.bashrc
93+
ENV PATH /opt/conda/envs/simrdwn/bin:$PATH
9694

9795
# install GPU version of tensorflow
98-
RUN source activate simrdwn2 && \
99-
conda install -n simrdwn2 -c defaults tensorflow-gpu=1.13.1
96+
RUN source activate simrdwn && \
97+
conda install -n simrdwn -c defaults tensorflow-gpu=1.13.1
10098

10199
# install keras with tf backend
102100
ENV KERAS_BACKEND=tensorflow
103-
RUN source activate simrdwn2 \
104-
&& conda install -n simrdwn2 keras
105-
106-
RUN conda install -n simrdwn2 \
107-
#awscli \
108-
affine \
109-
pyproj \
101+
RUN source activate simrdwn \
102+
&& conda install -n simrdwn keras=2.2.4
103+
104+
RUN source activate simrdwn \
105+
&& conda install -n simrdwn \
106+
libgdal=2.4.1 \
107+
gdal=2.4.1 \
108+
geopandas=0.5.0 \
109+
opencv=4.1.0 \
110+
affine=2.2.2 \
111+
pyproj=2.1.3 \
110112
pyhamcrest=1.9.0 \
111-
cython \
112-
contextlib2 \
113-
fiona \
114-
h5py \
115-
ncurses \
116-
jupyter \
117-
jupyterlab \
118-
ipykernel \
119-
libgdal \
120-
matplotlib \
121-
ncurses \
122-
numpy \
123-
#opencv=3.4.1 \
124-
#py-opencv \
125-
pandas \
126-
pillow \
127-
pip \
128-
scipy \
129-
scikit-image \
130-
scikit-learn \
131-
shapely \
132-
gdal \
133-
rtree \
134-
testpath \
135-
tqdm \
136-
pandas \
137-
geopandas \
138-
rasterio \
139-
opencv=4.0.0 \
113+
cython=0.29.10 \
114+
contextlib2=0.5.5 \
115+
h5py=2.9.0 \
116+
ncurses=6.1 \
117+
jupyter=1.0.0 \
118+
jupyterlab=0.35.6 \
119+
ipykernel=5.1.1 \
120+
matplotlib=3.1.0 \
121+
numpy=1.16.4 \
122+
pandas=0.24.2 \
123+
pillow=6.0.0 \
124+
pip=19.1.1 \
125+
scipy=1.3.0 \
126+
scikit-image=0.15.0 \
127+
scikit-learn=0.21.2 \
128+
shapely=1.6.4 \
129+
rtree=0.8.3 \
130+
testpath=0.4.2 \
131+
tqdm=4.32.1 \
132+
statsmodels=0.10.1 \
140133
&& conda clean -p \
141134
&& conda clean -t \
142135
&& conda clean --yes --all
143136

144-
RUN pip install statsmodels
137+
# Below is a hack to get around conda issues (2019-07-19)
138+
RUN source activate simrdwn \
139+
&& conda install -n simrdwn \
140+
-c conda-forge rasterio=1.0.24 \
141+
&& conda clean -p \
142+
&& conda clean -t \
143+
&& conda clean --yes --all
145144

146145
# tf object detection api
147146
RUN git clone https://github.com/tensorflow/models.git /tensorflow/models
147+
WORKDIR /tensorflow/models/research/
148+
RUN git checkout r1.13.0
148149
#WORKDIR /tensorflow/models/research/
149150
#RUN protoc object_detection/protos/*.proto --python_out=.
150151
# WORKDIR /tensorflow/models/research/
@@ -167,8 +168,28 @@ RUN export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim
167168
ENV PYTHONPATH $PYTHONPATH:/tensorflow/models/:/tensorflow/models/slim
168169
ENV PYTHONPATH $PYTHONPATH:/tensorflow/models/:/tensorflow/models/research/slim
169170

171+
# # this always seems to fail, so do it manually (as above)
172+
# RUN git clone https://github.com/cocodataset/cocoapi.git /cocoapi
173+
# WORKDIR /cocoapi/PythonAPI
174+
# RUN make
175+
# RUN cp -r pycocotools /tensorflow/models/research/
176+
# # From tensorflow/models/research/
177+
# WORKDIR /tensorflow/models/research/
178+
# RUN protoc object_detection/protos/*.proto --python_out=.
179+
180+
# # test
181+
# WORKDIR /tensorflow/models/research/
182+
# RUN PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim
183+
# RUN python /tensorflow/models/research/object_detection/builders/model_builder_test.py
184+
#
185+
# # RUN source activate simrdwn && \
186+
# # python /tensorflow/models/research/object_detection/builders/model_builder_test.py
187+
# # # ENV MODELS_DIR /tensorflow/models/research/
188+
# # # PYTHONPATH=${MODELS_DIR}/research:$MODELS_DIR/research/slim \
189+
# # #PYTHON $MODELS_DIR/research/object_detection/builders/model_builder_test.py
190+
170191
# # add a jupyter kernel for the conda environment in case it's wanted
171-
RUN source activate simrdwn2 && python -m ipykernel.kernelspec
192+
RUN source activate simrdwn && python -m ipykernel.kernelspec
172193
RUN python -m ipykernel.kernelspec
173194

174195

simrdwn/core/add_geo_coords.py

+19-9
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,12 @@ def add_geo_coords_to_df(df_, inProj_str='epsg:4326', outProj_str='epsg:3857',
185185
# raster geo transform
186186
gdal_geomTransform = gdal.Open(raster_loc).GetGeoTransform()
187187
affineObject = rio.open(raster_loc).transform
188+
188189
if verbose:
189190
print("raster_loc:", raster_loc)
190191
print("gdal_geomTransform:", gdal_geomTransform)
192+
print("gdal_geomTransform == (0.0, 1.0, 0.0, 0.0, 0.0, 1.0))",
193+
gdal_geomTransform == (0.0, 1.0, 0.0, 0.0, 0.0, 1.0))
191194
print("affineObject:", affineObject)
192195
geo_dict[raster_loc] = [gdal_geomTransform, affineObject]
193196

@@ -204,14 +207,21 @@ def add_geo_coords_to_df(df_, inProj_str='epsg:4326', outProj_str='epsg:3857',
204207
row['Xmin_Glob'], row['Ymin_Glob'],
205208
row['Xmax_Glob'], row['Ymax_Glob'])
206209

207-
out_arr_row, poly_geo = get_row_geo_coords(
208-
row, affineObject=affineObject,
209-
gdal_geomTransform=gdal_geomTransform,
210-
inProj_str=inProj_str, outProj_str=outProj_str,
211-
verbose=verbose)
212-
out_arr.append(out_arr_row)
213-
if create_geojson:
214-
out_arr_json.append(poly_geo)
210+
# check if the the image as geographic metadata
211+
if gdal_geomTransform == (0.0, 1.0, 0.0, 0.0, 0.0, 1.0):
212+
out_arr_row = 8 * [0]
213+
out_arr.append(out_arr_row)
214+
215+
# else, get geo locations
216+
else:
217+
out_arr_row, poly_geo = get_row_geo_coords(
218+
row, affineObject=affineObject,
219+
gdal_geomTransform=gdal_geomTransform,
220+
inProj_str=inProj_str, outProj_str=outProj_str,
221+
verbose=verbose)
222+
out_arr.append(out_arr_row)
223+
if create_geojson:
224+
out_arr_json.append(poly_geo)
215225

216226
# update dataframe
217227
# [lon0, lat0, lon1, lat1, x0_wmp, y0_wmp, x1_wmp, y1_wmp]
@@ -227,7 +237,7 @@ def add_geo_coords_to_df(df_, inProj_str='epsg:4326', outProj_str='epsg:3857',
227237

228238
# geodataframe if desired
229239
# https://gis.stackexchange.com/questions/174159/convert-a-pandas-dataframe-to-a-geodataframe
230-
if create_geojson:
240+
if create_geojson and (len(out_arr_json) > 0):
231241
crs_init = {'init': inProj_str}
232242
df_json = pd.DataFrame(out_arr_json, columns=['geometry'])
233243
# add important columns to df_json

simrdwn/core/infer_detections.py

+16-7
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@
6868
tf.flags.DEFINE_string('inference_graph', None,
6969
'Path to the inference graph with embedded weights.')
7070
tf.flags.DEFINE_boolean('verbose', False, 'Lots o print statements')
71-
tf.flags.DEFINE_boolean('use_tfrecords', True, 'Switch to use tfrecords')
72-
71+
tf.flags.DEFINE_boolean('use_tfrecords', False, 'Switch to use tfrecords')
7372

7473
# tfrecords
7574
tf.flags.DEFINE_string('input_tfrecord_paths', None,
@@ -97,8 +96,8 @@
9796
tf.flags.DEFINE_integer('BGR2RGB', 0,
9897
'Sometimes we need to change cv2 images to BGR')
9998

100-
10199
FLAGS = tf.flags.FLAGS
100+
# print("FLAGS:", FLAGS)
102101

103102

104103
###############################################################################
@@ -166,7 +165,7 @@ def main(_):
166165
str(t1 - t0) + ' seconds')
167166

168167
else:
169-
168+
# infer on csv
170169
if FLAGS.verbose:
171170
print("min_thresh:", FLAGS.min_thresh)
172171
t0 = time.time()
@@ -180,7 +179,7 @@ def main(_):
180179
tf.import_graph_def(graph_def, name='')
181180
print("Time to load graph:", time.time() - t0, "seconds")
182181

183-
with open(FLAGS.output_csv_path, 'wb') as csvfile:
182+
with open(FLAGS.output_csv_path, 'w') as csvfile:
184183
csvwriter = csv.writer(csvfile, delimiter=',')
185184
output_columns = ['Loc_Tmp', u'Prob', u'Xmin',
186185
u'Ymin', u'Xmax', u'Ymax', u'Category']
@@ -196,9 +195,19 @@ def main(_):
196195

197196
line_count = 0
198197
for i, image_path in enumerate(image_paths):
199-
200198
image_root = os.path.basename(image_path).strip()
201-
image_bgr = cv2.imread(image_path.strip(), 1)
199+
# print("image_path:", image_path)
200+
# print("str image_path.strip", str(image_path.strip()))
201+
# print("image_path.strip", image_path.strip().decode('utf-8'))
202+
#print("str image_path.strip", str(image_path.strip().decode('utf-8')))
203+
# print("os.path.exists image_path.strip", os.path.exists(image_path.strip()))
204+
# print("os.path.exists str image_path.strip", os.path.exists(str(image_path.strip())))
205+
# print("os.path.exists str image_path.strip", os.path.exists(str(image_path.strip()).strip()))
206+
# print("os.path.exists str image_path.strip", os.path.exists(str(image_path.strip().decode('utf-8'))))
207+
208+
# image_bgr = cv2.imread(image_path, cv2.IMREAD_COLOR)
209+
# image_bgr = cv2.imread(str(image_path.strip()), 1)
210+
image_bgr = cv2.imread(str(image_path.strip().decode('utf-8')), 1)
202211
# invert colors, if required
203212
if FLAGS.BGR2RGB == 1:
204213
image = cv2.cvtColor(image_bgr, cv2.COLOR_BGR2RGB)

simrdwn/core/post_process.py

+2
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,8 @@ def refine_df(df, groupby='Image_Path',
548548
if verbose:
549549
print("num boxes_all:", len(xmins))
550550
print("num good_idxs:", len(good_idxs))
551+
if len(boxes) == 0:
552+
print("Error, No boxes detected!")
551553
boxes = boxes[good_idxs]
552554
scores = scores[good_idxs]
553555
df_idxs = df_idxs[good_idxs]

0 commit comments

Comments
 (0)