Commit 7a9934df authored by Zhichao Lu's avatar Zhichao Lu Committed by lzc5123016
Browse files

Merged commit includes the following changes:

184048729  by Zhichao Lu:

    Modify target_assigner so that it creates regression targets taking keypoints into account.

--
184027183  by Zhichao Lu:

    Resnet V1 FPN based feature extractors for SSD meta architecture in Object Detection V2 API.

--
184004730  by Zhichao Lu:

    Expose a lever to override the configured mask_type.

--
183933113  by Zhichao Lu:

    Weight shared convolutional box predictor as described in https://arxiv.org/abs/1708.02002

--
183929669  by Zhichao Lu:

    Expanding box list operations for future data augmentations.

--
183916792  by Zhichao Lu:

    Fix unrecognized assertion function in tests.

--
183906851  by Zhichao Lu:

    - Change ssd meta architecture to use regression weights to compute loss normalizer.

--
183871003  by Zhichao Lu:

    Fix config_util_test wrong dependency.

--
183782120  by Zhichao Lu:

    Add __init__ file to third_party directories.

--
183779109  by Zhichao Lu:

    Setup regular version sync.

--
183768772  by Zhichao Lu:

    Make test compatible with numpy 1.12 and higher

--
183767893  by Zhichao Lu:

    Make test compatible with numpy 1.12 and higher

--
183719318  by Zhichao Lu:

    Use the new test interface in ssd feature extractor.

--
183714671  by Zhichao Lu:

    Use the new test_case interface for all anchor generators.

--
183708155  by Zhichao Lu:

    Change variable scopes in ConvolutionalBoxPredictor such that previously trained checkpoints are still compatible after the change in BoxPredictor interface

--
183705798  by Zhichao Lu:

    Internal change.

--
183636023  by Zhichao Lu:

    Fixing argument name for np_box_list_ops.concatenate() function.

--
183490404  by Zhichao Lu:

    Make sure code that relies in SSD older code still works.

--
183426762  by Zhichao Lu:

    Internal change

183412315  by Zhichao Lu:

    Internal change

183337814  by Zhichao Lu:

    Internal change

183303933  by Zhichao Lu:

    Internal change

183257349  by Zhichao Lu:

    Internal change

183254447  by Zhichao Lu:

    Internal change

183251200  by Zhichao Lu:

    Internal change

183135002  by Zhichao Lu:

    Internal change

182851500  by Zhichao Lu:

    Internal change

182839607  by Zhichao Lu:

    Internal change

182830719  by Zhichao Lu:

    Internal change

182533923  by Zhichao Lu:

    Internal change

182391090  by Zhichao Lu:

    Internal change

182262339  by Zhichao Lu:

    Internal change

182244645  by Zhichao Lu:

    Internal change

182241613  by Zhichao Lu:

    Internal change

182133027  by Zhichao Lu:

    Internal change

182058807  by Zhichao Lu:

    Internal change

181812028  by Zhichao Lu:

    Internal change

181788857  by Zhichao Lu:

    Internal change

181656761  by Zhichao Lu:

    Internal change

181541125  by Zhichao Lu:

    Internal change

181538702  by Zhichao Lu:

    Internal change

181125385  by Zhichao Lu:

    Internal change

180957758  by Zhichao Lu:

    Internal change

180941434  by Zhichao Lu:

    Internal change

180852569  by Zhichao Lu:

    Internal change

180846001  by Zhichao Lu:

    Internal change

180832145  by Zhichao Lu:

    Internal change

180740495  by Zhichao Lu:

    Internal change

180729150  by Zhichao Lu:

    Internal change

180589008  by Zhichao Lu:

    Internal change

180585408  by Zhichao Lu:

    Internal change

180581039  by Zhichao Lu:

    Internal change

180286388  by Zhichao Lu:

    Internal change

179934081  by Zhichao Lu:

    Internal change

179841242  by Zhichao Lu:

    Internal change

179831694  by Zhichao Lu:

    Internal change

179761005  by Zhichao Lu:

    Internal change

179610632  by Zhichao Lu:

    Internal change

179605363  by Zhichao Lu:

    Internal change

179603774  by Zhichao Lu:

    Internal change

179598614  by Zhichao Lu:

    Internal change

179597809  by Zhichao Lu:

    Internal change

179494630  by Zhichao Lu:

    Internal change

179367492  by Zhichao Lu:

    Internal change

179250050  by Zhichao Lu:

    Internal change

179247385  by Zhichao Lu:

    Internal change

179207897  by Zhichao Lu:

    Internal change

179076230  by Zhichao Lu:

    Internal change

178862066  by Zhichao Lu:

    Internal change

178854216  by Zhichao Lu:

    Internal change

178853109  by Zhichao Lu:

    Internal change

178709753  by Zhichao Lu:

    Internal change

178640707  by Zhichao Lu:

    Internal change

178421534  by Zhichao Lu:

    Internal change

178287174  by Zhichao Lu:

    Internal change

178257399  by Zhichao Lu:

    Internal change

177681867  by Zhichao Lu:

    Internal change

177654820  by Zhichao Lu:

    Internal change

177654052  by Zhichao Lu:

    Internal change

177638787  by Zhichao Lu:

    Internal change

177598305  by Zhichao Lu:

    Internal change

177538488  by Zhichao Lu:

    Internal change

177474197  by Zhichao Lu:

    Internal change

177271928  by Zhichao Lu:

    Internal change

177250285  by Zhichao Lu:

    Internal change

177210762  by Zhichao Lu:

    Internal change

177197135  by Zhichao Lu:

    Internal change

177037781  by Zhichao Lu:

    Internal change

176917394  by Zhichao Lu:

    Internal change

176683171  by Zhichao Lu:

    Internal change

176450793  by Zhichao Lu:

    Internal change

176388133  by Zhichao Lu:

    Internal change

176197721  by Zhichao Lu:

    Internal change

176195315  by Zhichao Lu:

    Internal change

176128748  by Zhichao Lu:

    Internal change

175743440  by Zhichao Lu:

    Use Toggle instead of bool to make the layout optimizer name and usage consistent with other optimizers.

--
175578178  by Zhichao Lu:

    Internal change

175463518  by Zhichao Lu:

    Internal change

175316616  by Zhichao Lu:

    Internal change

175302470  by Zhichao Lu:

    Internal change

175300323  by Zhichao Lu:

    Internal change

175269680  by Zhichao Lu:

    Internal change

175260574  by Zhichao Lu:

    Internal change

175122281  by Zhichao Lu:

    Internal change

175111708  by Zhichao Lu:

    Internal change

175110183  by Zhichao Lu:

    Internal change

174877166  by Zhichao Lu:

    Internal change

174868399  by Zhichao Lu:

    Internal change

174754200  by Zhichao Lu:

    Internal change

174544534  by Zhichao Lu:

    Internal change

174536143  by Zhichao Lu:

    Internal change

174513795  by Zhichao Lu:

    Internal change

174463713  by Zhichao Lu:

    Internal change

174403525  by Zhichao Lu:

    Internal change

174385170  by Zhichao Lu:

    Internal change

174358498  by Zhichao Lu:

    Internal change

174249903  by Zhichao Lu:

    Fix nasnet image classification and object detection by moving the option to turn ON or OFF batch norm training into it's own arg_scope used only by detection

--
174216508  by Zhichao Lu:

    Internal change

174065370  by Zhichao Lu:

    Internal change

174048035  by Zhichao Lu:

    Fix the pointer for downloading the NAS Faster-RCNN model.

--
174042677  by Zhichao Lu:

    Internal change

173964116  by Zhichao Lu:

    Internal change

173790182  by Zhichao Lu:

    Internal change

173779919  by Zhichao Lu:

    Internal change

173753775  by Zhichao Lu:

    Internal change

173753160  by Zhichao Lu:

    Internal change

173737519  by Zhichao Lu:

    Internal change

173696066  by Zhichao Lu:

    Internal change

173611554  by Zhichao Lu:

    Internal change

173475124  by Zhichao Lu:

    Internal change

173412497  by Zhichao Lu:

    Internal change

173404010  by Zhichao Lu:

    Internal change

173375014  by Zhichao Lu:

    Internal change

173345107  by Zhichao Lu:

    Internal change

173298413  by Zhichao Lu:

    Internal change

173289754  by Zhichao Lu:

    Internal change

173275544  by Zhichao Lu:

    Internal change

173273275  by Zhichao Lu:

    Internal change

173271885  by Zhichao Lu:

    Internal change

173264856  by Zhichao Lu:

    Internal change

173263791  by Zhichao Lu:

    Internal change

173261215  by Zhichao Lu:

    Internal change

173175740  by Zhichao Lu:

    Internal change

173010193  by Zhichao Lu:

    Internal change

172815204  by Zhichao Lu:

    Allow for label maps in tf.Example decoding.

--
172696028  by Zhichao Lu:

    Internal change

172509113  by Zhichao Lu:

    Allow for label maps in tf.Example decoding.

--
172475999  by Zhichao Lu:

    Internal change

172166621  by Zhichao Lu:

    Internal change

172151758  by Zhichao Lu:

    Minor updates to some README files.

    As a result of these friendly issues:
    https://github.com/tensorflow/models/issues/2530
    https://github.com/tensorflow/models/issues/2534

--
172147420  by Zhichao Lu:

    Fix illegal summary name and move from slim's get_or_create_global_step deprecated use of tf.contrib.framework* to tf.train*.

--
172111377  by Zhichao Lu:

    Internal change

172004247  by Zhichao Lu:

    Internal change

171996881  by Zhichao Lu:

    Internal change

171835204  by Zhichao Lu:

    Internal change

171826090  by Zhichao Lu:

    Internal change

171784016  by Zhichao Lu:

    Internal change

171699876  by Zhichao Lu:

    Internal change

171053425  by Zhichao Lu:

    Internal change

170905734  by Zhichao Lu:

    Internal change

170889179  by Zhichao Lu:

    Internal change

170734389  by Zhichao Lu:

    Internal change

170705852  by Zhichao Lu:

    Internal change

170401574  by Zhichao Lu:

    Internal change

170352571  by Zhichao Lu:

    Internal change

170215443  by Zhichao Lu:

    Internal change

170184288  by Zhichao Lu:

    Internal change

169936898  by Zhichao Lu:

    Internal change

169763373  by Zhichao Lu:

    Fix broken GitHub links in tensorflow and tensorflow_models resulting from The Great Models Move (a.k.a. the research subfolder)

--
169744825  by Zhichao Lu:

    Internal change

169638135  by Zhichao Lu:

    Internal change

169561814  by Zhichao Lu:

    Internal change

169444091  by Zhichao Lu:

    Internal change

169292330  by Zhichao Lu:

    Internal change

169145185  by Zhichao Lu:

    Internal change

168906035  by Zhichao Lu:

    Internal change

168790411  by Zhichao Lu:

    Internal change

168708911  by Zhichao Lu:

    Internal change

168611969  by Zhichao Lu:

    Internal change

168535975  by Zhichao Lu:

    Internal change

168381815  by Zhichao Lu:

    Internal change

168244740  by Zhichao Lu:

    Internal change

168240024  by Zhichao Lu:

    Internal change

168168016  by Zhichao Lu:

    Internal change

168071571  by Zhichao Lu:

    Move display strings to below the bounding box if they would otherwise be outside the image.

--
168067771  by Zhichao Lu:

    Internal change

167970950  by Zhichao Lu:

    Internal change

167884533  by Zhichao Lu:

    Internal change

167626173  by Zhichao Lu:

    Internal change

167277422  by Zhichao Lu:

    Internal change

167249393  by Zhichao Lu:

    Internal change

167248954  by Zhichao Lu:

    Internal change

167189395  by Zhichao Lu:

    Internal change

167107797  by Zhichao Lu:

    Internal change

167061250  by Zhichao Lu:

    Internal change

166871147  by Zhichao Lu:

    Internal change

166867617  by Zhichao Lu:

    Internal change

166862112  by Zhichao Lu:

    Internal change

166715648  by Zhichao Lu:

    Internal change

166635615  by Zhichao Lu:

    Internal change

166383182  by Zhichao Lu:

    Internal change

166371326  by Zhichao Lu:

    Internal change

166254711  by Zhichao Lu:

    Internal change

166106294  by Zhichao Lu:

    Internal change

166081204  by Zhichao Lu:

    Internal change

165972262  by Zhichao Lu:

    Internal change

165816702  by Zhichao Lu:

    Internal change

165764471  by Zhichao Lu:

    Internal change

165724134  by Zhichao Lu:

    Internal change

165655829  by Zhichao Lu:

    Internal change

165587904  by Zhichao Lu:

    Internal change

165534540  by Zhichao Lu:

    Internal change

165177692  by Zhichao Lu:

    Internal change

165091822  by Zhichao Lu:

    Internal change

165019730  by Zhichao Lu:

    Internal change

165002942  by Zhichao Lu:

    Internal change

164897728  by Zhichao Lu:

    Internal change

164782618  by Zhichao Lu:

    Internal change

164710379  by Zhichao Lu:

    Internal change

164639237  by Zhichao Lu:

    Internal change

164069251  by Zhichao Lu:

    Internal change

164058169  by Zhichao Lu:

    Internal change

163913796  by Zhichao Lu:

    Internal change

163756696  by Zhichao Lu:

    Internal change

163524665  by Zhichao Lu:

    Internal change

163393399  by Zhichao Lu:

    Internal change

163385733  by Zhichao Lu:

    Internal change

162525065  by Zhichao Lu:

    Internal change

162376984  by Zhichao Lu:

    Internal change

162026661  by Zhichao Lu:

    Internal change

161956004  by Zhichao Lu:

    Internal change

161817520  by Zhichao Lu:

    Internal change

161718688  by Zhichao Lu:

    Internal change

161624398  by Zhichao Lu:

    Internal change

161575120  by Zhichao Lu:

    Internal change

161483997  by Zhichao Lu:

    Internal change

161462189  by Zhichao Lu:

    Internal change

161452968  by Zhichao Lu:

    Internal change

161443992  by Zhichao Lu:

    Internal change

161408607  by Zhichao Lu:

    Internal change

161262084  by Zhichao Lu:

    Internal change

161214023  by Zhichao Lu:

    Internal change

161025667  by Zhichao Lu:

    Internal change

160982216  by Zhichao Lu:

    Internal change

160666760  by Zhichao Lu:

    Internal change

160570489  by Zhichao Lu:

    Internal change

160553112  by Zhichao Lu:

    Internal change

160458261  by Zhichao Lu:

    Internal change

160349302  by Zhichao Lu:

    Internal change

160296092  by Zhichao Lu:

    Internal change

160287348  by Zhichao Lu:

    Internal change

160199279  by Zhichao Lu:

    Internal change

160160156  by Zhichao Lu:

    Internal change

160151954  by Zhichao Lu:

    Internal change

160005404  by Zhichao Lu:

    Internal change

159983265  by Zhichao Lu:

    Internal change

159819896  by Zhichao Lu:

    Internal change

159749419  by Zhichao Lu:

    Internal change

159596448  by Zhichao Lu:

    Internal change

159587801  by Zhichao Lu:

    Internal change

159587342  by Zhichao Lu:

    Internal change

159476256  by Zhichao Lu:

    Internal change

159463992  by Zhichao Lu:

    Internal change

159455585  by Zhichao Lu:

    Internal change

159270798  by Zhichao Lu:

    Internal change

159256633  by Zhichao Lu:

    Internal change

159141989  by Zhichao Lu:

    Internal change

159079098  by Zhichao Lu:

    Internal change

159078559  by Zhichao Lu:

    Internal change

159077055  by Zhichao Lu:

    Internal change

159072046  by Zhichao Lu:

    Internal change

159071092  by Zhichao Lu:

    Internal change

159069262  by Zhichao Lu:

    Internal change

159037430  by Zhichao Lu:

    Internal change

159035747  by Zhichao Lu:

    Internal change

159023868  by Zhichao Lu:

    Internal change

158939092  by Zhichao Lu:

    Internal change

158912561  by Zhichao Lu:

    Internal change

158903825  by Zhichao Lu:

    Internal change

158894348  by Zhichao Lu:

    Internal change

158884934  by Zhichao Lu:

    Internal change

158878010  by Zhichao Lu:

    Internal change

158874620  by Zhichao Lu:

    Internal change

158869501  by Zhichao Lu:

    Internal change

158842623  by Zhichao Lu:

    Internal change

158801298  by Zhichao Lu:

    Internal change

158775487  by Zhichao Lu:

    Internal change

158773668  by Zhichao Lu:

    Internal change

158771394  by Zhichao Lu:

    Internal change

158668928  by Zhichao Lu:

    Internal change

158596865  by Zhichao Lu:

    Internal change

158587317  by Zhichao Lu:

    Internal change

158586348  by Zhichao Lu:

    Internal change

158585707  by Zhichao Lu:

    Internal change

158577134  by Zhichao Lu:

    Internal change

158459749  by Zhichao Lu:

    Internal change

158459678  by Zhichao Lu:

    Internal change

158328972  by Zhichao Lu:

    Internal change

158324255  by Zhichao Lu:

    Internal change

158319576  by Zhichao Lu:

    Internal change

158290802  by Zhichao Lu:

    Internal change

158273041  by Zhichao Lu:

    Internal change

158240477  by Zhichao Lu:

    Internal change

158204316  by Zhichao Lu:

    Internal change

158154161  by Zhichao Lu:

    Internal change

158077203  by Zhichao Lu:

    Internal change

158041397  by Zhichao Lu:

    Internal change

158029233  by Zhichao Lu:

    Internal change

157976306  by Zhichao Lu:

    Internal change

157966896  by Zhichao Lu:

    Internal change

157945642  by Zhichao Lu:

    Internal change

157943135  by Zhichao Lu:

    Internal change

157942158  by Zhichao Lu:

    Internal change

157897866  by Zhichao Lu:

    Internal change

157866667  by Zhichao Lu:

    Internal change

157845915  by Zhichao Lu:

    Internal change

157842592  by Zhichao Lu:

    Internal change

157832761  by Zhichao Lu:

    Internal change

157824451  by Zhichao Lu:

    Internal change

157816531  by Zhichao Lu:

    Internal change

157782130  by Zhichao Lu:

    Internal change

157733752  by Zhichao Lu:

    Internal change

157654577  by Zhichao Lu:

    Internal change

157639285  by Zhichao Lu:

    Internal change

157530694  by Zhichao Lu:

    Internal change

157518469  by Zhichao Lu:

    Internal change

157514626  by Zhichao Lu:

    Internal change

157481413  by Zhichao Lu:

    Internal change

157267863  by Zhichao Lu:

    Internal change

157263616  by Zhichao Lu:

    Internal change

157234554  by Zhichao Lu:

    Internal change

157174595  by Zhichao Lu:

    Internal change

157169681  by Zhichao Lu:

    Internal change

157156425  by Zhichao Lu:

    Internal change

157024436  by Zhichao Lu:

    Internal change

157016195  by Zhichao Lu:

    Internal change

156941658  by Zhichao Lu:

    Internal change

156880859  by Zhichao Lu:

    Internal change

156790636  by Zhichao Lu:

    Internal change

156565969  by Zhichao Lu:

    Internal change

156522345  by Zhichao Lu:

    Internal change

156518570  by Zhichao Lu:

    Internal change

156509878  by Zhichao Lu:

    Internal change

156509134  by Zhichao Lu:

    Internal change

156472497  by Zhichao Lu:

    Internal change

156471429  by Zhichao Lu:

    Internal change

156470865  by Zhichao Lu:

    Internal change

156461563  by Zhichao Lu:

    Internal change

156437521  by Zhichao Lu:

    Internal change

156334994  by Zhichao Lu:

    Internal change

156319604  by Zhichao Lu:

    Internal change

156234305  by Zhichao Lu:

    Internal change

156226207  by Zhichao Lu:

    Internal change

156215347  by Zhichao Lu:

    Internal change

156127227  by Zhichao Lu:

    Internal change

156120405  by Zhichao Lu:

    Internal change

156113752  by Zhichao Lu:

    Internal change

156098936  by Zhichao Lu:

    Internal change

155924066  by Zhichao Lu:

    Internal change

155883241  by Zhichao Lu:

    Internal change

155806887  by Zhichao Lu:

    Internal change

155641849  by Zhichao Lu:

    Internal change

155593034  by Zhichao Lu:

    Internal change

155570702  by Zhichao Lu:

    Internal change

155515306  by Zhichao Lu:

    Internal change

155514787  by Zhichao Lu:

    Internal change

155445237  by Zhichao Lu:

    Internal change

155438672  by Zhichao Lu:

    Internal change

155264448  by Zhichao Lu:

    Internal change

155222148  by Zhichao Lu:

    Internal change

155106590  by Zhichao Lu:

    Internal change

155090562  by Zhichao Lu:

    Internal change

154973775  by Zhichao Lu:

    Internal change

154972880  by Zhichao Lu:

    Internal change

154871596  by Zhichao Lu:

    Internal change

154835007  by Zhichao Lu:

    Internal change

154788175  by Zhichao Lu:

    Internal change

154731169  by Zhichao Lu:

    Internal change

154721261  by Zhichao Lu:

    Internal change

154594626  by Zhichao Lu:

    Internal change

154588305  by Zhichao Lu:

    Internal change

154578994  by Zhichao Lu:

    Internal change

154571515  by Zhichao Lu:

    Internal change

154552873  by Zhichao Lu:

    Internal change

154549672  by Zhichao Lu:

    Internal change

154463631  by Zhichao Lu:

    Internal change

154437690  by Zhichao Lu:

    Internal change

154412359  by Zhichao Lu:

    Internal change

154374026  by Zhichao Lu:

    Internal change

154361648  by Zhichao Lu:

    Internal change

154310164  by Zhichao Lu:

    Internal change

154220862  by Zhichao Lu:

    Internal change

154187281  by Zhichao Lu:

    Internal change

154186651  by Zhichao Lu:

    Internal change

154119783  by Zhichao Lu:

    Internal change

154114285  by Zhichao Lu:

    Internal change

154095717  by Zhichao Lu:

    Internal change

154057972  by Zhichao Lu:

    Internal change

154055285  by Zhichao Lu:

    Internal change

153659288  by Zhichao Lu:

    Internal change

153637797  by Zhichao Lu:

    Internal change

153561771  by Zhichao Lu:

    Internal change

153540765  by Zhichao Lu:

    Internal change

153496128  by Zhichao Lu:

    Internal change

153473323  by Zhichao Lu:

    Internal change

153368812  by Zhichao Lu:

    Internal change

153367292  by Zhichao Lu:

    Internal change

153201890  by Zhichao Lu:

    Internal change

153074177  by Zhichao Lu:

    Internal change

152980017  by Zhichao Lu:

    Internal change

152978434  by Zhichao Lu:

    Internal change

152951821  by Zhichao Lu:

    Internal change

152904076  by Zhichao Lu:

    Internal change

152883703  by Zhichao Lu:

    Internal change

152869747  by Zhichao Lu:

    Internal change

152827463  by Zhichao Lu:

    Internal change

152756886  by Zhichao Lu:

    Internal change

152752840  by Zhichao Lu:

    Internal change

152736347  by Zhichao Lu:

    Internal change

152728184  by Zhichao Lu:

    Internal change

152720120  by Zhichao Lu:

    Internal change

152710964  by Zhichao Lu:

    Internal change

152706735  by Zhichao Lu:

    Internal change

152681133  by Zhichao Lu:

    Internal change

152517758  by Zhichao Lu:

    Internal change

152516381  by Zhichao Lu:

    Internal change

152511258  by Zhichao Lu:

    Internal change

152319164  by Zhichao Lu:

    Internal change

152316404  by Zhichao Lu:

    Internal change

152309261  by Zhichao Lu:

    Internal change

152308007  by Zhichao Lu:

    Internal change

152296551  by Zhichao Lu:

    Internal change

152188069  by Zhichao Lu:

    Internal change

152158644  by Zhichao Lu:

    Internal change

152153578  by Zhichao Lu:

    Internal change

152152285  by Zhichao Lu:

    Internal change

152055035  by Zhichao Lu:

    Internal change

152036778  by Zhichao Lu:

    Internal change

152020728  by Zhichao Lu:

    Internal change

152014842  by Zhichao Lu:

    Internal change

151848225  by Zhichao Lu:

    Internal change

151741308  by Zhichao Lu:

    Internal change

151740499  by Zhichao Lu:

    Internal change

151736189  by Zhichao Lu:

    Internal change

151612892  by Zhichao Lu:

    Internal change

151599502  by Zhichao Lu:

    Internal change

151538547  by Zhichao Lu:

    Internal change

151496530  by Zhichao Lu:

    Internal change

151476070  by Zhichao Lu:

    Internal change

151448662  by Zhichao Lu:

    Internal change

151411627  by Zhichao Lu:

    Internal change

151397737  by Zhichao Lu:

    Internal change

151169523  by Zhichao Lu:

    Internal change

151148956  by Zhichao Lu:

    Internal change

150944227  by Zhichao Lu:

    Internal change

150276683  by Zhichao Lu:

    Internal change

149986687  by Zhichao Lu:

    Internal change

149218749  by Zhichao Lu:

    Internal change

PiperOrigin-RevId: 184048729
parent 7ef602be
...@@ -7,6 +7,43 @@ package( ...@@ -7,6 +7,43 @@ package(
licenses(["notice"]) licenses(["notice"])
# Apache 2.0 # Apache 2.0
py_library(
name = "inputs",
srcs = [
"inputs.py",
],
deps = [
"//tensorflow",
"//tensorflow/models/research/object_detection:trainer",
"//tensorflow/models/research/object_detection/builders:dataset_builder",
"//tensorflow/models/research/object_detection/builders:preprocessor_builder",
"//tensorflow/models/research/object_detection/protos:input_reader_py_pb2",
"//tensorflow/models/research/object_detection/protos:train_py_pb2",
"//tensorflow/models/research/object_detection/utils:dataset_util",
"//tensorflow/models/research/object_detection/utils:ops",
],
)
py_test(
name = "inputs_test",
srcs = [
"inputs_test.py",
],
data = [
"//tensorflow/models/research/object_detection/data:pet_label_map.pbtxt",
"//tensorflow/models/research/object_detection/samples/configs:faster_rcnn_resnet50_pets.config",
"//tensorflow/models/research/object_detection/samples/configs:ssd_inception_v2_pets.config",
"//tensorflow/models/research/object_detection/test_data:pets_examples.record",
],
deps = [
":inputs",
"//tensorflow",
"//tensorflow/models/research/object_detection/core:standard_fields",
"//tensorflow/models/research/object_detection/utils:config_util",
],
)
py_binary( py_binary(
name = "train", name = "train",
srcs = [ srcs = [
...@@ -15,9 +52,10 @@ py_binary( ...@@ -15,9 +52,10 @@ py_binary(
deps = [ deps = [
":trainer", ":trainer",
"//tensorflow", "//tensorflow",
"//tensorflow_models/object_detection/builders:input_reader_builder", "//tensorflow/models/research/object_detection/builders:dataset_builder",
"//tensorflow_models/object_detection/builders:model_builder", "//tensorflow/models/research/object_detection/builders:model_builder",
"//tensorflow_models/object_detection/utils:config_util", "//tensorflow/models/research/object_detection/utils:config_util",
"//tensorflow/models/research/object_detection/utils:dataset_util",
], ],
) )
...@@ -26,14 +64,14 @@ py_library( ...@@ -26,14 +64,14 @@ py_library(
srcs = ["trainer.py"], srcs = ["trainer.py"],
deps = [ deps = [
"//tensorflow", "//tensorflow",
"//tensorflow_models/object_detection/builders:optimizer_builder", "//tensorflow/models/research/object_detection/builders:optimizer_builder",
"//tensorflow_models/object_detection/builders:preprocessor_builder", "//tensorflow/models/research/object_detection/builders:preprocessor_builder",
"//tensorflow_models/object_detection/core:batcher", "//tensorflow/models/research/object_detection/core:batcher",
"//tensorflow_models/object_detection/core:preprocessor", "//tensorflow/models/research/object_detection/core:preprocessor",
"//tensorflow_models/object_detection/core:standard_fields", "//tensorflow/models/research/object_detection/core:standard_fields",
"//tensorflow_models/object_detection/utils:ops", "//tensorflow/models/research/object_detection/utils:ops",
"//tensorflow_models/object_detection/utils:variables_helper", "//tensorflow/models/research/object_detection/utils:variables_helper",
"//tensorflow_models/slim:model_deploy", "//third_party/tensorflow_models/slim:model_deploy",
], ],
) )
...@@ -43,10 +81,10 @@ py_test( ...@@ -43,10 +81,10 @@ py_test(
deps = [ deps = [
":trainer", ":trainer",
"//tensorflow", "//tensorflow",
"//tensorflow_models/object_detection/core:losses", "//tensorflow/models/research/object_detection/core:losses",
"//tensorflow_models/object_detection/core:model", "//tensorflow/models/research/object_detection/core:model",
"//tensorflow_models/object_detection/core:standard_fields", "//tensorflow/models/research/object_detection/core:standard_fields",
"//tensorflow_models/object_detection/protos:train_py_pb2", "//tensorflow/models/research/object_detection/protos:train_py_pb2",
], ],
) )
...@@ -57,13 +95,13 @@ py_library( ...@@ -57,13 +95,13 @@ py_library(
], ],
deps = [ deps = [
"//tensorflow", "//tensorflow",
"//tensorflow_models/object_detection/core:box_list", "//tensorflow/models/research/object_detection/core:box_list",
"//tensorflow_models/object_detection/core:box_list_ops", "//tensorflow/models/research/object_detection/core:box_list_ops",
"//tensorflow_models/object_detection/core:keypoint_ops", "//tensorflow/models/research/object_detection/core:keypoint_ops",
"//tensorflow_models/object_detection/core:standard_fields", "//tensorflow/models/research/object_detection/core:standard_fields",
"//tensorflow_models/object_detection/utils:label_map_util", "//tensorflow/models/research/object_detection/utils:label_map_util",
"//tensorflow_models/object_detection/utils:ops", "//tensorflow/models/research/object_detection/utils:ops",
"//tensorflow_models/object_detection/utils:visualization_utils", "//tensorflow/models/research/object_detection/utils:visualization_utils",
], ],
) )
...@@ -72,11 +110,11 @@ py_library( ...@@ -72,11 +110,11 @@ py_library(
srcs = ["evaluator.py"], srcs = ["evaluator.py"],
deps = [ deps = [
"//tensorflow", "//tensorflow",
"//tensorflow_models/object_detection:eval_util", "//tensorflow/models/research/object_detection:eval_util",
"//tensorflow_models/object_detection/core:prefetcher", "//tensorflow/models/research/object_detection/core:prefetcher",
"//tensorflow_models/object_detection/core:standard_fields", "//tensorflow/models/research/object_detection/core:standard_fields",
"//tensorflow_models/object_detection/protos:eval_py_pb2", "//tensorflow/models/research/object_detection/protos:eval_py_pb2",
"//tensorflow_models/object_detection/utils:object_detection_evaluation", "//tensorflow/models/research/object_detection/utils:object_detection_evaluation",
], ],
) )
...@@ -88,10 +126,11 @@ py_binary( ...@@ -88,10 +126,11 @@ py_binary(
deps = [ deps = [
":evaluator", ":evaluator",
"//tensorflow", "//tensorflow",
"//tensorflow_models/object_detection/builders:input_reader_builder", "//tensorflow/models/research/object_detection/builders:dataset_builder",
"//tensorflow_models/object_detection/builders:model_builder", "//tensorflow/models/research/object_detection/builders:model_builder",
"//tensorflow_models/object_detection/utils:config_util", "//tensorflow/models/research/object_detection/utils:config_util",
"//tensorflow_models/object_detection/utils:label_map_util", "//tensorflow/models/research/object_detection/utils:dataset_util",
"//tensorflow/models/research/object_detection/utils:label_map_util",
], ],
) )
...@@ -103,9 +142,9 @@ py_library( ...@@ -103,9 +142,9 @@ py_library(
deps = [ deps = [
"//tensorflow", "//tensorflow",
"//tensorflow/python/tools:freeze_graph_lib", "//tensorflow/python/tools:freeze_graph_lib",
"//tensorflow_models/object_detection/builders:model_builder", "//tensorflow/models/research/object_detection/builders:model_builder",
"//tensorflow_models/object_detection/core:standard_fields", "//tensorflow/models/research/object_detection/core:standard_fields",
"//tensorflow_models/object_detection/data_decoders:tf_example_decoder", "//tensorflow/models/research/object_detection/data_decoders:tf_example_decoder",
], ],
) )
...@@ -117,9 +156,9 @@ py_test( ...@@ -117,9 +156,9 @@ py_test(
deps = [ deps = [
":exporter", ":exporter",
"//tensorflow", "//tensorflow",
"//tensorflow_models/object_detection/builders:model_builder", "//tensorflow/models/research/object_detection/builders:model_builder",
"//tensorflow_models/object_detection/core:model", "//tensorflow/models/research/object_detection/core:model",
"//tensorflow_models/object_detection/protos:pipeline_py_pb2", "//tensorflow/models/research/object_detection/protos:pipeline_py_pb2",
], ],
) )
...@@ -131,6 +170,6 @@ py_binary( ...@@ -131,6 +170,6 @@ py_binary(
deps = [ deps = [
":exporter", ":exporter",
"//tensorflow", "//tensorflow",
"//tensorflow_models/object_detection/protos:pipeline_py_pb2", "//tensorflow/models/research/object_detection/protos:pipeline_py_pb2",
], ],
) )
...@@ -32,6 +32,7 @@ https://scholar.googleusercontent.com/scholar.bib?q=info:l291WsrB-hQJ:scholar.go ...@@ -32,6 +32,7 @@ https://scholar.googleusercontent.com/scholar.bib?q=info:l291WsrB-hQJ:scholar.go
* Derek Chow, github: [derekjchow](https://github.com/derekjchow) * Derek Chow, github: [derekjchow](https://github.com/derekjchow)
* Chen Sun, github: [jesu9](https://github.com/jesu9) * Chen Sun, github: [jesu9](https://github.com/jesu9)
* Menglong Zhu, github: [dreamdragon](https://github.com/dreamdragon) * Menglong Zhu, github: [dreamdragon](https://github.com/dreamdragon)
* Alireza Fathi, github: [afathi3](https://github.com/afathi3)
## Table of contents ## Table of contents
......
...@@ -14,9 +14,9 @@ py_library( ...@@ -14,9 +14,9 @@ py_library(
], ],
deps = [ deps = [
"//tensorflow", "//tensorflow",
"//tensorflow_models/object_detection/core:anchor_generator", "//tensorflow/models/research/object_detection/core:anchor_generator",
"//tensorflow_models/object_detection/core:box_list", "//tensorflow/models/research/object_detection/core:box_list",
"//tensorflow_models/object_detection/utils:ops", "//tensorflow/models/research/object_detection/utils:ops",
], ],
) )
...@@ -28,6 +28,7 @@ py_test( ...@@ -28,6 +28,7 @@ py_test(
deps = [ deps = [
":grid_anchor_generator", ":grid_anchor_generator",
"//tensorflow", "//tensorflow",
"//tensorflow/models/research/object_detection/utils:test_case",
], ],
) )
...@@ -39,8 +40,8 @@ py_library( ...@@ -39,8 +40,8 @@ py_library(
deps = [ deps = [
":grid_anchor_generator", ":grid_anchor_generator",
"//tensorflow", "//tensorflow",
"//tensorflow_models/object_detection/core:anchor_generator", "//tensorflow/models/research/object_detection/core:anchor_generator",
"//tensorflow_models/object_detection/core:box_list_ops", "//tensorflow/models/research/object_detection/core:box_list_ops",
], ],
) )
...@@ -51,6 +52,32 @@ py_test( ...@@ -51,6 +52,32 @@ py_test(
], ],
deps = [ deps = [
":multiple_grid_anchor_generator", ":multiple_grid_anchor_generator",
"//third_party/py/numpy", "//numpy",
"//tensorflow/models/research/object_detection/utils:test_case",
],
)
py_library(
name = "multiscale_grid_anchor_generator",
srcs = [
"multiscale_grid_anchor_generator.py",
],
deps = [
":grid_anchor_generator",
"//tensorflow",
"//tensorflow/models/research/object_detection/core:anchor_generator",
"//tensorflow/models/research/object_detection/core:box_list_ops",
],
)
py_test(
name = "multiscale_grid_anchor_generator_test",
srcs = [
"multiscale_grid_anchor_generator_test.py",
],
deps = [
":multiscale_grid_anchor_generator",
"//numpy",
"//tensorflow/models/research/object_detection/utils:test_case",
], ],
) )
...@@ -42,25 +42,27 @@ class GridAnchorGenerator(anchor_generator.AnchorGenerator): ...@@ -42,25 +42,27 @@ class GridAnchorGenerator(anchor_generator.AnchorGenerator):
scales: a list of (float) scales, default=(0.5, 1.0, 2.0) scales: a list of (float) scales, default=(0.5, 1.0, 2.0)
aspect_ratios: a list of (float) aspect ratios, default=(0.5, 1.0, 2.0) aspect_ratios: a list of (float) aspect ratios, default=(0.5, 1.0, 2.0)
base_anchor_size: base anchor size as height, width ( base_anchor_size: base anchor size as height, width (
(length-2 float32 list, default=[256, 256]) (length-2 float32 list or tensor, default=[256, 256])
anchor_stride: difference in centers between base anchors for adjacent anchor_stride: difference in centers between base anchors for adjacent
grid positions (length-2 float32 list, default=[16, 16]) grid positions (length-2 float32 list or tensor,
default=[16, 16])
anchor_offset: center of the anchor with scale and aspect ratio 1 for the anchor_offset: center of the anchor with scale and aspect ratio 1 for the
upper left element of the grid, this should be zero for upper left element of the grid, this should be zero for
feature networks with only VALID padding and even receptive feature networks with only VALID padding and even receptive
field size, but may need additional calculation if other field size, but may need additional calculation if other
padding is used (length-2 float32 tensor, default=[0, 0]) padding is used (length-2 float32 list or tensor,
default=[0, 0])
""" """
# Handle argument defaults # Handle argument defaults
if base_anchor_size is None: if base_anchor_size is None:
base_anchor_size = [256, 256] base_anchor_size = [256, 256]
base_anchor_size = tf.constant(base_anchor_size, tf.float32) base_anchor_size = tf.to_float(tf.convert_to_tensor(base_anchor_size))
if anchor_stride is None: if anchor_stride is None:
anchor_stride = [16, 16] anchor_stride = [16, 16]
anchor_stride = tf.constant(anchor_stride, dtype=tf.float32) anchor_stride = tf.to_float(tf.convert_to_tensor(anchor_stride))
if anchor_offset is None: if anchor_offset is None:
anchor_offset = [0, 0] anchor_offset = [0, 0]
anchor_offset = tf.constant(anchor_offset, dtype=tf.float32) anchor_offset = tf.to_float(tf.convert_to_tensor(anchor_offset))
self._scales = scales self._scales = scales
self._aspect_ratios = aspect_ratios self._aspect_ratios = aspect_ratios
...@@ -91,7 +93,11 @@ class GridAnchorGenerator(anchor_generator.AnchorGenerator): ...@@ -91,7 +93,11 @@ class GridAnchorGenerator(anchor_generator.AnchorGenerator):
allowed. allowed.
Returns: Returns:
boxes: a BoxList holding a collection of N anchor boxes boxes: a BoxList holding a collection of N anchor boxes. Additionally
this BoxList also holds a `feature_map_index` field which is set to 0
for each anchor; this field exists for interchangeability reasons with
the MultipleGridAnchorGenerator (see the docstring for the corresponding
`_generate` function in multiple_grid_anchor_generator.py)
Raises: Raises:
ValueError: if feature_map_shape_list, box_specs_list do not have the same ValueError: if feature_map_shape_list, box_specs_list do not have the same
length. length.
...@@ -109,13 +115,20 @@ class GridAnchorGenerator(anchor_generator.AnchorGenerator): ...@@ -109,13 +115,20 @@ class GridAnchorGenerator(anchor_generator.AnchorGenerator):
self._aspect_ratios) self._aspect_ratios)
scales_grid = tf.reshape(scales_grid, [-1]) scales_grid = tf.reshape(scales_grid, [-1])
aspect_ratios_grid = tf.reshape(aspect_ratios_grid, [-1]) aspect_ratios_grid = tf.reshape(aspect_ratios_grid, [-1])
return tile_anchors(grid_height, anchors = tile_anchors(grid_height,
grid_width, grid_width,
scales_grid, scales_grid,
aspect_ratios_grid, aspect_ratios_grid,
self._base_anchor_size, self._base_anchor_size,
self._anchor_stride, self._anchor_stride,
self._anchor_offset) self._anchor_offset)
num_anchors = anchors.num_boxes_static()
if num_anchors is None:
num_anchors = anchors.num_boxes()
anchor_indices = tf.zeros([num_anchors])
anchors.add_field('feature_map_index', anchor_indices)
return anchors
def tile_anchors(grid_height, def tile_anchors(grid_height,
......
...@@ -14,62 +14,90 @@ ...@@ -14,62 +14,90 @@
# ============================================================================== # ==============================================================================
"""Tests for object_detection.grid_anchor_generator.""" """Tests for object_detection.grid_anchor_generator."""
import numpy as np
import tensorflow as tf import tensorflow as tf
from object_detection.anchor_generators import grid_anchor_generator from object_detection.anchor_generators import grid_anchor_generator
from object_detection.utils import test_case
class GridAnchorGeneratorTest(tf.test.TestCase): class GridAnchorGeneratorTest(test_case.TestCase):
def test_construct_single_anchor(self): def test_construct_single_anchor(self):
"""Builds a 1x1 anchor grid to test the size of the output boxes.""" """Builds a 1x1 anchor grid to test the size of the output boxes."""
scales = [0.5, 1.0, 2.0] def graph_fn():
aspect_ratios = [0.25, 1.0, 4.0] scales = [0.5, 1.0, 2.0]
anchor_offset = [7, -3] aspect_ratios = [0.25, 1.0, 4.0]
anchor_offset = [7, -3]
anchor_generator = grid_anchor_generator.GridAnchorGenerator(
scales, aspect_ratios, anchor_offset=anchor_offset)
anchors = anchor_generator.generate(feature_map_shape_list=[(1, 1)])
anchor_corners = anchors.get()
return (anchor_corners,)
exp_anchor_corners = [[-121, -35, 135, 29], [-249, -67, 263, 61], exp_anchor_corners = [[-121, -35, 135, 29], [-249, -67, 263, 61],
[-505, -131, 519, 125], [-57, -67, 71, 61], [-505, -131, 519, 125], [-57, -67, 71, 61],
[-121, -131, 135, 125], [-249, -259, 263, 253], [-121, -131, 135, 125], [-249, -259, 263, 253],
[-25, -131, 39, 125], [-57, -259, 71, 253], [-25, -131, 39, 125], [-57, -259, 71, 253],
[-121, -515, 135, 509]] [-121, -515, 135, 509]]
anchor_corners_out = self.execute(graph_fn, [])
anchor_generator = grid_anchor_generator.GridAnchorGenerator( self.assertAllClose(anchor_corners_out, exp_anchor_corners)
scales, aspect_ratios,
anchor_offset=anchor_offset)
anchors = anchor_generator.generate(feature_map_shape_list=[(1, 1)])
anchor_corners = anchors.get()
with self.test_session():
anchor_corners_out = anchor_corners.eval()
self.assertAllClose(anchor_corners_out, exp_anchor_corners)
def test_construct_anchor_grid(self): def test_construct_anchor_grid(self):
base_anchor_size = [10, 10] def graph_fn():
anchor_stride = [19, 19] base_anchor_size = [10, 10]
anchor_offset = [0, 0] anchor_stride = [19, 19]
scales = [0.5, 1.0, 2.0] anchor_offset = [0, 0]
aspect_ratios = [1.0] scales = [0.5, 1.0, 2.0]
aspect_ratios = [1.0]
anchor_generator = grid_anchor_generator.GridAnchorGenerator(
scales,
aspect_ratios,
base_anchor_size=base_anchor_size,
anchor_stride=anchor_stride,
anchor_offset=anchor_offset)
anchors = anchor_generator.generate(feature_map_shape_list=[(2, 2)])
anchor_corners = anchors.get()
return (anchor_corners,)
exp_anchor_corners = [[-2.5, -2.5, 2.5, 2.5], [-5., -5., 5., 5.], exp_anchor_corners = [[-2.5, -2.5, 2.5, 2.5], [-5., -5., 5., 5.],
[-10., -10., 10., 10.], [-2.5, 16.5, 2.5, 21.5], [-10., -10., 10., 10.], [-2.5, 16.5, 2.5, 21.5],
[-5., 14., 5, 24], [-10., 9., 10, 29], [-5., 14., 5, 24], [-10., 9., 10, 29],
[16.5, -2.5, 21.5, 2.5], [14., -5., 24, 5], [16.5, -2.5, 21.5, 2.5], [14., -5., 24, 5],
[9., -10., 29, 10], [16.5, 16.5, 21.5, 21.5], [9., -10., 29, 10], [16.5, 16.5, 21.5, 21.5],
[14., 14., 24, 24], [9., 9., 29, 29]] [14., 14., 24, 24], [9., 9., 29, 29]]
anchor_corners_out = self.execute(graph_fn, [])
self.assertAllClose(anchor_corners_out, exp_anchor_corners)
anchor_generator = grid_anchor_generator.GridAnchorGenerator( def test_construct_anchor_grid_with_dynamic_feature_map_shapes(self):
scales, def graph_fn(feature_map_height, feature_map_width):
aspect_ratios, base_anchor_size = [10, 10]
base_anchor_size=base_anchor_size, anchor_stride = [19, 19]
anchor_stride=anchor_stride, anchor_offset = [0, 0]
anchor_offset=anchor_offset) scales = [0.5, 1.0, 2.0]
aspect_ratios = [1.0]
anchor_generator = grid_anchor_generator.GridAnchorGenerator(
scales,
aspect_ratios,
base_anchor_size=base_anchor_size,
anchor_stride=anchor_stride,
anchor_offset=anchor_offset)
anchors = anchor_generator.generate(feature_map_shape_list=[(2, 2)]) anchors = anchor_generator.generate(
anchor_corners = anchors.get() feature_map_shape_list=[(feature_map_height, feature_map_width)])
anchor_corners = anchors.get()
return (anchor_corners,)
with self.test_session(): exp_anchor_corners = [[-2.5, -2.5, 2.5, 2.5], [-5., -5., 5., 5.],
anchor_corners_out = anchor_corners.eval() [-10., -10., 10., 10.], [-2.5, 16.5, 2.5, 21.5],
self.assertAllClose(anchor_corners_out, exp_anchor_corners) [-5., 14., 5, 24], [-10., 9., 10, 29],
[16.5, -2.5, 21.5, 2.5], [14., -5., 24, 5],
[9., -10., 29, 10], [16.5, 16.5, 21.5, 21.5],
[14., 14., 24, 24], [9., 9., 29, 29]]
anchor_corners_out = self.execute_cpu(graph_fn,
[np.array(2, dtype=np.int32),
np.array(2, dtype=np.int32)])
self.assertAllClose(anchor_corners_out, exp_anchor_corners)
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -165,7 +165,10 @@ class MultipleGridAnchorGenerator(anchor_generator.AnchorGenerator): ...@@ -165,7 +165,10 @@ class MultipleGridAnchorGenerator(anchor_generator.AnchorGenerator):
grid. grid.
Returns: Returns:
boxes: a BoxList holding a collection of N anchor boxes boxes: a BoxList holding a collection of N anchor boxes. Additionally
this BoxList also holds a `feature_map_index` field which, for each
anchor, stores the index of the corresponding feature map which was used
to generate it.
Raises: Raises:
ValueError: if feature_map_shape_list, box_specs_list do not have the same ValueError: if feature_map_shape_list, box_specs_list do not have the same
length. length.
...@@ -208,6 +211,7 @@ class MultipleGridAnchorGenerator(anchor_generator.AnchorGenerator): ...@@ -208,6 +211,7 @@ class MultipleGridAnchorGenerator(anchor_generator.AnchorGenerator):
raise ValueError('%s must be a list of pairs.' % arg_name) raise ValueError('%s must be a list of pairs.' % arg_name)
anchor_grid_list = [] anchor_grid_list = []
anchor_indices_list = []
min_im_shape = tf.minimum(im_height, im_width) min_im_shape = tf.minimum(im_height, im_width)
scale_height = min_im_shape / im_height scale_height = min_im_shape / im_height
scale_width = min_im_shape / im_width scale_width = min_im_shape / im_width
...@@ -215,32 +219,40 @@ class MultipleGridAnchorGenerator(anchor_generator.AnchorGenerator): ...@@ -215,32 +219,40 @@ class MultipleGridAnchorGenerator(anchor_generator.AnchorGenerator):
scale_height * self._base_anchor_size[0], scale_height * self._base_anchor_size[0],
scale_width * self._base_anchor_size[1] scale_width * self._base_anchor_size[1]
] ]
for grid_size, scales, aspect_ratios, stride, offset in zip( for feature_map_index, (
feature_map_shape_list, self._scales, self._aspect_ratios, grid_size, scales, aspect_ratios, stride, offset) in enumerate(
anchor_strides, anchor_offsets): zip(feature_map_shape_list, self._scales, self._aspect_ratios,
anchor_grid_list.append( anchor_strides, anchor_offsets)):
grid_anchor_generator.tile_anchors( tiled_anchors = grid_anchor_generator.tile_anchors(
grid_height=grid_size[0], grid_height=grid_size[0],
grid_width=grid_size[1], grid_width=grid_size[1],
scales=scales, scales=scales,
aspect_ratios=aspect_ratios, aspect_ratios=aspect_ratios,
base_anchor_size=base_anchor_size, base_anchor_size=base_anchor_size,
anchor_stride=stride, anchor_stride=stride,
anchor_offset=offset)) anchor_offset=offset)
anchor_grid_list.append(tiled_anchors)
num_anchors_in_layer = tiled_anchors.num_boxes_static()
if num_anchors_in_layer is None:
num_anchors_in_layer = tiled_anchors.num_boxes()
anchor_indices_list.append(
feature_map_index * tf.ones([num_anchors_in_layer]))
concatenated_anchors = box_list_ops.concatenate(anchor_grid_list) concatenated_anchors = box_list_ops.concatenate(anchor_grid_list)
anchor_indices = tf.concat(anchor_indices_list, 0)
num_anchors = concatenated_anchors.num_boxes_static() num_anchors = concatenated_anchors.num_boxes_static()
if num_anchors is None: if num_anchors is None:
num_anchors = concatenated_anchors.num_boxes() num_anchors = concatenated_anchors.num_boxes()
if self._clip_window is not None: if self._clip_window is not None:
concatenated_anchors = box_list_ops.clip_to_window( concatenated_anchors = box_list_ops.clip_to_window(
concatenated_anchors, self._clip_window, filter_nonoverlapping=False) concatenated_anchors, self._clip_window, filter_nonoverlapping=False)
# TODO(jonathanhuang): make reshape an option for the clip_to_window op # TODO: make reshape an option for the clip_to_window op
concatenated_anchors.set( concatenated_anchors.set(
tf.reshape(concatenated_anchors.get(), [num_anchors, 4])) tf.reshape(concatenated_anchors.get(), [num_anchors, 4]))
stddevs_tensor = 0.01 * tf.ones( stddevs_tensor = 0.01 * tf.ones(
[num_anchors, 4], dtype=tf.float32, name='stddevs') [num_anchors, 4], dtype=tf.float32, name='stddevs')
concatenated_anchors.add_field('stddev', stddevs_tensor) concatenated_anchors.add_field('stddev', stddevs_tensor)
concatenated_anchors.add_field('feature_map_index', anchor_indices)
return concatenated_anchors return concatenated_anchors
......
...@@ -20,35 +20,45 @@ import numpy as np ...@@ -20,35 +20,45 @@ import numpy as np
import tensorflow as tf import tensorflow as tf
from object_detection.anchor_generators import multiple_grid_anchor_generator as ag from object_detection.anchor_generators import multiple_grid_anchor_generator as ag
from object_detection.utils import test_case
class MultipleGridAnchorGeneratorTest(tf.test.TestCase): class MultipleGridAnchorGeneratorTest(test_case.TestCase):
def test_construct_single_anchor_grid(self): def test_construct_single_anchor_grid(self):
"""Builds a 1x1 anchor grid to test the size of the output boxes.""" """Builds a 1x1 anchor grid to test the size of the output boxes."""
def graph_fn():
box_specs_list = [[(.5, .25), (1.0, .25), (2.0, .25),
(.5, 1.0), (1.0, 1.0), (2.0, 1.0),
(.5, 4.0), (1.0, 4.0), (2.0, 4.0)]]
anchor_generator = ag.MultipleGridAnchorGenerator(
box_specs_list,
base_anchor_size=tf.constant([256, 256], dtype=tf.float32),
anchor_strides=[(16, 16)],
anchor_offsets=[(7, -3)])
anchors = anchor_generator.generate(feature_map_shape_list=[(1, 1)])
return anchors.get()
exp_anchor_corners = [[-121, -35, 135, 29], [-249, -67, 263, 61], exp_anchor_corners = [[-121, -35, 135, 29], [-249, -67, 263, 61],
[-505, -131, 519, 125], [-57, -67, 71, 61], [-505, -131, 519, 125], [-57, -67, 71, 61],
[-121, -131, 135, 125], [-249, -259, 263, 253], [-121, -131, 135, 125], [-249, -259, 263, 253],
[-25, -131, 39, 125], [-57, -259, 71, 253], [-25, -131, 39, 125], [-57, -259, 71, 253],
[-121, -515, 135, 509]] [-121, -515, 135, 509]]
box_specs_list = [[(.5, .25), (1.0, .25), (2.0, .25), anchor_corners_out = self.execute(graph_fn, [])
(.5, 1.0), (1.0, 1.0), (2.0, 1.0), self.assertAllClose(anchor_corners_out, exp_anchor_corners)
(.5, 4.0), (1.0, 4.0), (2.0, 4.0)]]
anchor_generator = ag.MultipleGridAnchorGenerator(
box_specs_list,
base_anchor_size=tf.constant([256, 256], dtype=tf.float32),
anchor_strides=[(16, 16)],
anchor_offsets=[(7, -3)])
anchors = anchor_generator.generate(feature_map_shape_list=[(1, 1)])
anchor_corners = anchors.get()
with self.test_session():
anchor_corners_out = anchor_corners.eval()
self.assertAllClose(anchor_corners_out, exp_anchor_corners)
def test_construct_anchor_grid(self): def test_construct_anchor_grid(self):
box_specs_list = [[(0.5, 1.0), (1.0, 1.0), (2.0, 1.0)]] def graph_fn():
box_specs_list = [[(0.5, 1.0), (1.0, 1.0), (2.0, 1.0)]]
anchor_generator = ag.MultipleGridAnchorGenerator(
box_specs_list,
base_anchor_size=tf.constant([10, 10], dtype=tf.float32),
anchor_strides=[(19, 19)],
anchor_offsets=[(0, 0)])
anchors = anchor_generator.generate(feature_map_shape_list=[(2, 2)])
return anchors.get()
exp_anchor_corners = [[-2.5, -2.5, 2.5, 2.5], [-5., -5., 5., 5.], exp_anchor_corners = [[-2.5, -2.5, 2.5, 2.5], [-5., -5., 5., 5.],
[-10., -10., 10., 10.], [-2.5, 16.5, 2.5, 21.5], [-10., -10., 10., 10.], [-2.5, 16.5, 2.5, 21.5],
[-5., 14., 5, 24], [-10., 9., 10, 29], [-5., 14., 5, 24], [-10., 9., 10, 29],
...@@ -56,55 +66,74 @@ class MultipleGridAnchorGeneratorTest(tf.test.TestCase): ...@@ -56,55 +66,74 @@ class MultipleGridAnchorGeneratorTest(tf.test.TestCase):
[9., -10., 29, 10], [16.5, 16.5, 21.5, 21.5], [9., -10., 29, 10], [16.5, 16.5, 21.5, 21.5],
[14., 14., 24, 24], [9., 9., 29, 29]] [14., 14., 24, 24], [9., 9., 29, 29]]
anchor_generator = ag.MultipleGridAnchorGenerator( anchor_corners_out = self.execute(graph_fn, [])
box_specs_list, self.assertAllClose(anchor_corners_out, exp_anchor_corners)
base_anchor_size=tf.constant([10, 10], dtype=tf.float32),
anchor_strides=[(19, 19)],
anchor_offsets=[(0, 0)])
anchors = anchor_generator.generate(feature_map_shape_list=[(2, 2)])
anchor_corners = anchors.get()
with self.test_session():
anchor_corners_out = anchor_corners.eval()
self.assertAllClose(anchor_corners_out, exp_anchor_corners)
def test_construct_anchor_grid_non_square(self): def test_construct_anchor_grid_non_square(self):
box_specs_list = [[(1.0, 1.0)]]
def graph_fn():
box_specs_list = [[(1.0, 1.0)]]
anchor_generator = ag.MultipleGridAnchorGenerator(
box_specs_list, base_anchor_size=tf.constant([1, 1],
dtype=tf.float32))
anchors = anchor_generator.generate(feature_map_shape_list=[(tf.constant(
1, dtype=tf.int32), tf.constant(2, dtype=tf.int32))])
return anchors.get()
exp_anchor_corners = [[0., -0.25, 1., 0.75], [0., 0.25, 1., 1.25]] exp_anchor_corners = [[0., -0.25, 1., 0.75], [0., 0.25, 1., 1.25]]
anchor_corners_out = self.execute(graph_fn, [])
self.assertAllClose(anchor_corners_out, exp_anchor_corners)
anchor_generator = ag.MultipleGridAnchorGenerator( def test_construct_dynamic_size_anchor_grid(self):
box_specs_list, base_anchor_size=tf.constant([1, 1], dtype=tf.float32))
anchors = anchor_generator.generate(feature_map_shape_list=[(tf.constant(
1, dtype=tf.int32), tf.constant(2, dtype=tf.int32))])
anchor_corners = anchors.get()
with self.test_session(): def graph_fn(height, width):
anchor_corners_out = anchor_corners.eval() box_specs_list = [[(1.0, 1.0)]]
self.assertAllClose(anchor_corners_out, exp_anchor_corners) anchor_generator = ag.MultipleGridAnchorGenerator(
box_specs_list, base_anchor_size=tf.constant([1, 1],
dtype=tf.float32))
anchors = anchor_generator.generate(feature_map_shape_list=[(height,
width)])
return anchors.get()
def test_construct_anchor_grid_normalized(self): exp_anchor_corners = [[0., -0.25, 1., 0.75], [0., 0.25, 1., 1.25]]
box_specs_list = [[(1.0, 1.0)]]
exp_anchor_corners = [[0., 0., 1., 0.5], [0., 0.5, 1., 1.]] anchor_corners_out = self.execute_cpu(graph_fn,
[np.array(1, dtype=np.int32),
np.array(2, dtype=np.int32)])
self.assertAllClose(anchor_corners_out, exp_anchor_corners)
anchor_generator = ag.MultipleGridAnchorGenerator( def test_construct_anchor_grid_normalized(self):
box_specs_list, base_anchor_size=tf.constant([1, 1], dtype=tf.float32)) def graph_fn():
anchors = anchor_generator.generate( box_specs_list = [[(1.0, 1.0)]]
feature_map_shape_list=[(tf.constant(1, dtype=tf.int32), tf.constant(
2, dtype=tf.int32))], anchor_generator = ag.MultipleGridAnchorGenerator(
im_height=320, box_specs_list, base_anchor_size=tf.constant([1, 1],
im_width=640) dtype=tf.float32))
anchor_corners = anchors.get() anchors = anchor_generator.generate(
feature_map_shape_list=[(tf.constant(1, dtype=tf.int32), tf.constant(
2, dtype=tf.int32))],
im_height=320,
im_width=640)
return anchors.get()
with self.test_session(): exp_anchor_corners = [[0., 0., 1., 0.5], [0., 0.5, 1., 1.]]
anchor_corners_out = anchor_corners.eval() anchor_corners_out = self.execute(graph_fn, [])
self.assertAllClose(anchor_corners_out, exp_anchor_corners) self.assertAllClose(anchor_corners_out, exp_anchor_corners)
def test_construct_multiple_grids(self): def test_construct_multiple_grids(self):
box_specs_list = [[(1.0, 1.0), (2.0, 1.0), (1.0, 0.5)],
[(1.0, 1.0), (1.0, 0.5)]]
def graph_fn():
box_specs_list = [[(1.0, 1.0), (2.0, 1.0), (1.0, 0.5)],
[(1.0, 1.0), (1.0, 0.5)]]
anchor_generator = ag.MultipleGridAnchorGenerator(
box_specs_list,
base_anchor_size=tf.constant([1.0, 1.0], dtype=tf.float32),
anchor_strides=[(.25, .25), (.5, .5)],
anchor_offsets=[(.125, .125), (.25, .25)])
anchors = anchor_generator.generate(feature_map_shape_list=[(4, 4),
(2, 2)])
return anchors.get()
# height and width of box with .5 aspect ratio # height and width of box with .5 aspect ratio
h = np.sqrt(2) h = np.sqrt(2)
w = 1.0/np.sqrt(2) w = 1.0/np.sqrt(2)
...@@ -121,26 +150,27 @@ class MultipleGridAnchorGeneratorTest(tf.test.TestCase): ...@@ -121,26 +150,27 @@ class MultipleGridAnchorGeneratorTest(tf.test.TestCase):
[.125-1.0, .125-1.0, .125+1.0, .125+1.0], [.125-1.0, .125-1.0, .125+1.0, .125+1.0],
[.125-.5*h, .125-.5*w, .125+.5*h, .125+.5*w],] [.125-.5*h, .125-.5*w, .125+.5*h, .125+.5*w],]
anchor_generator = ag.MultipleGridAnchorGenerator( anchor_corners_out = self.execute(graph_fn, [])
box_specs_list, self.assertEquals(anchor_corners_out.shape, (56, 4))
base_anchor_size=tf.constant([1.0, 1.0], dtype=tf.float32), big_grid_corners = anchor_corners_out[0:3, :]
anchor_strides=[(.25, .25), (.5, .5)], small_grid_corners = anchor_corners_out[48:, :]
anchor_offsets=[(.125, .125), (.25, .25)]) self.assertAllClose(small_grid_corners, exp_small_grid_corners)
anchors = anchor_generator.generate(feature_map_shape_list=[(4, 4), (2, 2)]) self.assertAllClose(big_grid_corners, exp_big_grid_corners)
anchor_corners = anchors.get()
with self.test_session():
anchor_corners_out = anchor_corners.eval()
self.assertEquals(anchor_corners_out.shape, (56, 4))
big_grid_corners = anchor_corners_out[0:3, :]
small_grid_corners = anchor_corners_out[48:, :]
self.assertAllClose(small_grid_corners, exp_small_grid_corners)
self.assertAllClose(big_grid_corners, exp_big_grid_corners)
def test_construct_multiple_grids_with_clipping(self): def test_construct_multiple_grids_with_clipping(self):
box_specs_list = [[(1.0, 1.0), (2.0, 1.0), (1.0, 0.5)],
[(1.0, 1.0), (1.0, 0.5)]]
def graph_fn():
box_specs_list = [[(1.0, 1.0), (2.0, 1.0), (1.0, 0.5)],
[(1.0, 1.0), (1.0, 0.5)]]
clip_window = tf.constant([0, 0, 1, 1], dtype=tf.float32)
anchor_generator = ag.MultipleGridAnchorGenerator(
box_specs_list,
base_anchor_size=tf.constant([1.0, 1.0], dtype=tf.float32),
clip_window=clip_window)
anchors = anchor_generator.generate(feature_map_shape_list=[(4, 4),
(2, 2)])
return anchors.get()
# height and width of box with .5 aspect ratio # height and width of box with .5 aspect ratio
h = np.sqrt(2) h = np.sqrt(2)
w = 1.0/np.sqrt(2) w = 1.0/np.sqrt(2)
...@@ -153,18 +183,9 @@ class MultipleGridAnchorGeneratorTest(tf.test.TestCase): ...@@ -153,18 +183,9 @@ class MultipleGridAnchorGeneratorTest(tf.test.TestCase):
[.25, .25, 1, 1], [.25, .25, 1, 1],
[.75-.5*h, .75-.5*w, 1, 1]] [.75-.5*h, .75-.5*w, 1, 1]]
clip_window = tf.constant([0, 0, 1, 1], dtype=tf.float32) anchor_corners_out = self.execute(graph_fn, [])
anchor_generator = ag.MultipleGridAnchorGenerator( small_grid_corners = anchor_corners_out[48:, :]
box_specs_list, self.assertAllClose(small_grid_corners, exp_small_grid_corners)
base_anchor_size=tf.constant([1.0, 1.0], dtype=tf.float32),
clip_window=clip_window)
anchors = anchor_generator.generate(feature_map_shape_list=[(4, 4), (2, 2)])
anchor_corners = anchors.get()
with self.test_session():
anchor_corners_out = anchor_corners.eval()
small_grid_corners = anchor_corners_out[48:, :]
self.assertAllClose(small_grid_corners, exp_small_grid_corners)
def test_invalid_box_specs(self): def test_invalid_box_specs(self):
# not all box specs are pairs # not all box specs are pairs
...@@ -229,38 +250,39 @@ class MultipleGridAnchorGeneratorTest(tf.test.TestCase): ...@@ -229,38 +250,39 @@ class MultipleGridAnchorGeneratorTest(tf.test.TestCase):
anchor_generator.generate(feature_map_shape_list=[(4), (2, 2)]) anchor_generator.generate(feature_map_shape_list=[(4), (2, 2)])
class CreateSSDAnchorsTest(tf.test.TestCase): class CreateSSDAnchorsTest(test_case.TestCase):
def test_create_ssd_anchors_returns_correct_shape(self): def test_create_ssd_anchors_returns_correct_shape(self):
anchor_generator = ag.create_ssd_anchors(
num_layers=6, def graph_fn1():
min_scale=0.2, anchor_generator = ag.create_ssd_anchors(
max_scale=0.95, num_layers=6,
aspect_ratios=(1.0, 2.0, 3.0, 1.0 / 2, 1.0 / 3), min_scale=0.2,
reduce_boxes_in_lowest_layer=True) max_scale=0.95,
aspect_ratios=(1.0, 2.0, 3.0, 1.0 / 2, 1.0 / 3),
feature_map_shape_list = [(38, 38), (19, 19), (10, 10), reduce_boxes_in_lowest_layer=True)
(5, 5), (3, 3), (1, 1)]
anchors = anchor_generator.generate( feature_map_shape_list = [(38, 38), (19, 19), (10, 10),
feature_map_shape_list=feature_map_shape_list) (5, 5), (3, 3), (1, 1)]
anchor_corners = anchors.get() anchors = anchor_generator.generate(
with self.test_session(): feature_map_shape_list=feature_map_shape_list)
anchor_corners_out = anchor_corners.eval() return anchors.get()
self.assertEquals(anchor_corners_out.shape, (7308, 4)) anchor_corners_out = self.execute(graph_fn1, [])
self.assertEquals(anchor_corners_out.shape, (7308, 4))
anchor_generator = ag.create_ssd_anchors(
num_layers=6, min_scale=0.2, max_scale=0.95, def graph_fn2():
aspect_ratios=(1.0, 2.0, 3.0, 1.0/2, 1.0/3), anchor_generator = ag.create_ssd_anchors(
reduce_boxes_in_lowest_layer=False) num_layers=6, min_scale=0.2, max_scale=0.95,
aspect_ratios=(1.0, 2.0, 3.0, 1.0/2, 1.0/3),
feature_map_shape_list = [(38, 38), (19, 19), (10, 10), reduce_boxes_in_lowest_layer=False)
(5, 5), (3, 3), (1, 1)]
anchors = anchor_generator.generate( feature_map_shape_list = [(38, 38), (19, 19), (10, 10),
feature_map_shape_list=feature_map_shape_list) (5, 5), (3, 3), (1, 1)]
anchor_corners = anchors.get() anchors = anchor_generator.generate(
with self.test_session(): feature_map_shape_list=feature_map_shape_list)
anchor_corners_out = anchor_corners.eval() return anchors.get()
self.assertEquals(anchor_corners_out.shape, (11640, 4)) anchor_corners_out = self.execute(graph_fn2, [])
self.assertEquals(anchor_corners_out.shape, (11640, 4))
if __name__ == '__main__': if __name__ == '__main__':
......
# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Generates grid anchors on the fly corresponding to multiple CNN layers.
Generates grid anchors on the fly corresponding to multiple CNN layers as
described in:
"Focal Loss for Dense Object Detection"
T.-Y. Lin, P. Goyal, R. Girshick, K. He, P. Dollar
"""
from object_detection.anchor_generators import grid_anchor_generator
from object_detection.core import box_list_ops
class MultiscaleGridAnchorGenerator(object):
"""Generate a grid of anchors for multiple CNN layers."""
def __init__(self, min_level, max_level, anchor_scale, aspect_ratios,
scales_per_octave):
"""Constructs a MultiscaleGridAnchorGenerator.
To construct anchors, at multiple scale resolutions, one must provide a
the minimum level and maximum levels on a scale pyramid. To define the size
of anchor, the anchor scale is provided to decide the size relatively to the
stride of the corresponding feature map. The generator allows one pixel
location on feature map maps to multiple anchors, that have different aspect
ratios and intermediate scales.
Args:
min_level: minimum level in feature pyramid.
max_level: maximum level in feature pyramid.
anchor_scale: anchor scale and feature stride define the size of the base
anchor on an image. For example, given a feature pyramid with strides
[2^3, ..., 2^7] and anchor scale 4. The base anchor size is
4 * [2^3, ..., 2^7].
aspect_ratios: list or tuple of (float) aspect ratios to place on each
grid point.
scales_per_octave: integer number of intermediate scales per scale octave.
"""
self._anchor_grid_info = []
self._aspect_ratios = aspect_ratios
self._scales_per_octave = scales_per_octave
for level in range(min_level, max_level + 1):
anchor_stride = [2**level, 2**level]
scales = []
aspects = []
for scale in range(scales_per_octave):
scales.append(2**(float(scale) / scales_per_octave))
for aspect_ratio in aspect_ratios:
aspects.append(aspect_ratio)
base_anchor_size = [2**level * anchor_scale, 2**level * anchor_scale]
self._anchor_grid_info.append({
'level': level,
'info': [scales, aspects, base_anchor_size, anchor_stride]
})
def name_scope(self):
return 'MultiscaleGridAnchorGenerator'
def num_anchors_per_location(self):
"""Returns the number of anchors per spatial location.
Returns:
a list of integers, one for each expected feature map to be passed to
the Generate function.
"""
return self._aspect_ratios * self._scales_per_octave
def generate(self, feature_map_shape_list, im_height, im_width):
"""Generates a collection of bounding boxes to be used as anchors.
Args:
feature_map_shape_list: list of pairs of convnet layer resolutions in the
format [(height_0, width_0), (height_1, width_1), ...]. For example,
setting feature_map_shape_list=[(8, 8), (7, 7)] asks for anchors that
correspond to an 8x8 layer followed by a 7x7 layer.
im_height: the height of the image to generate the grid for.
im_width: the width of the image to generate the grid for.
Returns:
boxes: a BoxList holding a collection of N anchor boxes
"""
anchor_grid_list = []
for feat_shape, grid_info in zip(feature_map_shape_list,
self._anchor_grid_info):
# TODO check the feature_map_shape_list is consistent with
# self._anchor_grid_info
level = grid_info['level']
stride = 2**level
scales, aspect_ratios, base_anchor_size, anchor_stride = grid_info['info']
feat_h = feat_shape[0]
feat_w = feat_shape[1]
anchor_offset = [0, 0]
if im_height % 2.0**level == 0:
anchor_offset[0] = stride / 2.0
if im_width % 2.0**level == 0:
anchor_offset[1] = stride / 2.0
ag = grid_anchor_generator.GridAnchorGenerator(
scales,
aspect_ratios,
base_anchor_size=base_anchor_size,
anchor_stride=anchor_stride,
anchor_offset=anchor_offset)
anchor_grid_list.append(
ag.generate(feature_map_shape_list=[(feat_h, feat_w)]))
concatenated_anchors = box_list_ops.concatenate(anchor_grid_list)
return concatenated_anchors
# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Tests for anchor_generators.multiscale_grid_anchor_generator_test.py."""
import numpy as np
import tensorflow as tf
from object_detection.anchor_generators import multiscale_grid_anchor_generator as mg
from object_detection.utils import test_case
class MultiscaleGridAnchorGeneratorTest(test_case.TestCase):
def test_construct_single_anchor(self):
min_level = 5
max_level = 5
anchor_scale = 4.0
aspect_ratios = [1.0]
scales_per_octave = 1
im_height = 64
im_width = 64
feature_map_shape_list = [(2, 2)]
exp_anchor_corners = [[-48, -48, 80, 80],
[-48, -16, 80, 112],
[-16, -48, 112, 80],
[-16, -16, 112, 112]]
anchor_generator = mg.MultiscaleGridAnchorGenerator(
min_level, max_level, anchor_scale, aspect_ratios, scales_per_octave)
anchors = anchor_generator.generate(feature_map_shape_list,
im_height, im_width)
anchor_corners = anchors.get()
with self.test_session():
anchor_corners_out = anchor_corners.eval()
self.assertAllClose(anchor_corners_out, exp_anchor_corners)
def test_construct_single_anchor_with_odd_input_dimension(self):
def graph_fn():
min_level = 5
max_level = 5
anchor_scale = 4.0
aspect_ratios = [1.0]
scales_per_octave = 1
im_height = 65
im_width = 65
feature_map_shape_list = [(3, 3)]
anchor_generator = mg.MultiscaleGridAnchorGenerator(
min_level, max_level, anchor_scale, aspect_ratios, scales_per_octave)
anchors = anchor_generator.generate(feature_map_shape_list, im_height,
im_width)
anchor_corners = anchors.get()
return (anchor_corners,)
anchor_corners_out = self.execute(graph_fn, [])
exp_anchor_corners = [[-64, -64, 64, 64],
[-64, -32, 64, 96],
[-64, 0, 64, 128],
[-32, -64, 96, 64],
[-32, -32, 96, 96],
[-32, 0, 96, 128],
[0, -64, 128, 64],
[0, -32, 128, 96],
[0, 0, 128, 128]]
self.assertAllClose(anchor_corners_out, exp_anchor_corners)
def test_construct_single_anchor_on_two_feature_maps(self):
def graph_fn():
min_level = 5
max_level = 6
anchor_scale = 4.0
aspect_ratios = [1.0]
scales_per_octave = 1
im_height = 64
im_width = 64
feature_map_shape_list = [(2, 2), (1, 1)]
anchor_generator = mg.MultiscaleGridAnchorGenerator(
min_level, max_level, anchor_scale, aspect_ratios, scales_per_octave)
anchors = anchor_generator.generate(feature_map_shape_list, im_height,
im_width)
anchor_corners = anchors.get()
return (anchor_corners,)
anchor_corners_out = self.execute(graph_fn, [])
exp_anchor_corners = [[-48, -48, 80, 80],
[-48, -16, 80, 112],
[-16, -48, 112, 80],
[-16, -16, 112, 112],
[-96, -96, 160, 160]]
self.assertAllClose(anchor_corners_out, exp_anchor_corners)
def test_construct_single_anchor_with_two_scales_per_octave(self):
def graph_fn():
min_level = 6
max_level = 6
anchor_scale = 4.0
aspect_ratios = [1.0]
scales_per_octave = 2
im_height = 64
im_width = 64
feature_map_shape_list = [(1, 1), (1, 1)]
anchor_generator = mg.MultiscaleGridAnchorGenerator(
min_level, max_level, anchor_scale, aspect_ratios, scales_per_octave)
anchors = anchor_generator.generate(feature_map_shape_list, im_height,
im_width)
anchor_corners = anchors.get()
return (anchor_corners,)
# There are 4 set of anchors in this configuration. The order is:
# [[2**0.0 intermediate scale + 1.0 aspect],
# [2**0.5 intermediate scale + 1.0 aspect]]
exp_anchor_corners = [[-96., -96., 160., 160.],
[-149.0193, -149.0193, 213.0193, 213.0193]]
anchor_corners_out = self.execute(graph_fn, [])
self.assertAllClose(anchor_corners_out, exp_anchor_corners)
def test_construct_single_anchor_with_two_scales_per_octave_and_aspect(self):
def graph_fn():
min_level = 6
max_level = 6
anchor_scale = 4.0
aspect_ratios = [1.0, 2.0]
scales_per_octave = 2
im_height = 64
im_width = 64
feature_map_shape_list = [(1, 1), (1, 1), (1, 1), (1, 1)]
anchor_generator = mg.MultiscaleGridAnchorGenerator(
min_level, max_level, anchor_scale, aspect_ratios, scales_per_octave)
anchors = anchor_generator.generate(feature_map_shape_list, im_height,
im_width)
anchor_corners = anchors.get()
return anchor_corners
# There are 4 set of anchors in this configuration. The order is:
# [[2**0.0 intermediate scale + 1.0 aspect],
# [2**0.5 intermediate scale + 1.0 aspect],
# [2**0.0 intermediate scale + 2.0 aspect],
# [2**0.5 intermediate scale + 2.0 aspect]]
exp_anchor_corners = [[-96., -96., 160., 160.],
[-149.0193, -149.0193, 213.0193, 213.0193],
[-58.50967, -149.0193, 122.50967, 213.0193],
[-96., -224., 160., 288.]]
anchor_corners_out = self.execute(graph_fn, [])
self.assertAllClose(anchor_corners_out, exp_anchor_corners)
def test_construct_single_anchors_on_feature_maps_with_dynamic_shape(self):
def graph_fn(feature_map1_height, feature_map1_width, feature_map2_height,
feature_map2_width):
min_level = 5
max_level = 6
anchor_scale = 4.0
aspect_ratios = [1.0]
scales_per_octave = 1
im_height = 64
im_width = 64
feature_map_shape_list = [(feature_map1_height, feature_map1_width),
(feature_map2_height, feature_map2_width)]
anchor_generator = mg.MultiscaleGridAnchorGenerator(
min_level, max_level, anchor_scale, aspect_ratios, scales_per_octave)
anchors = anchor_generator.generate(feature_map_shape_list, im_height,
im_width)
anchor_corners = anchors.get()
return (anchor_corners,)
anchor_corners_out = self.execute_cpu(graph_fn, [
np.array(2, dtype=np.int32),
np.array(2, dtype=np.int32),
np.array(1, dtype=np.int32),
np.array(1, dtype=np.int32)
])
exp_anchor_corners = [[-48, -48, 80, 80],
[-48, -16, 80, 112],
[-16, -48, 112, 80],
[-16, -16, 112, 112],
[-96, -96, 160, 160]]
self.assertAllClose(anchor_corners_out, exp_anchor_corners)
if __name__ == '__main__':
tf.test.main()
...@@ -13,8 +13,8 @@ py_library( ...@@ -13,8 +13,8 @@ py_library(
"faster_rcnn_box_coder.py", "faster_rcnn_box_coder.py",
], ],
deps = [ deps = [
"//tensorflow_models/object_detection/core:box_coder", "//tensorflow/models/research/object_detection/core:box_coder",
"//tensorflow_models/object_detection/core:box_list", "//tensorflow/models/research/object_detection/core:box_list",
], ],
) )
...@@ -26,7 +26,7 @@ py_test( ...@@ -26,7 +26,7 @@ py_test(
deps = [ deps = [
":faster_rcnn_box_coder", ":faster_rcnn_box_coder",
"//tensorflow", "//tensorflow",
"//tensorflow_models/object_detection/core:box_list", "//tensorflow/models/research/object_detection/core:box_list",
], ],
) )
...@@ -36,9 +36,9 @@ py_library( ...@@ -36,9 +36,9 @@ py_library(
"keypoint_box_coder.py", "keypoint_box_coder.py",
], ],
deps = [ deps = [
"//tensorflow_models/object_detection/core:box_coder", "//tensorflow/models/research/object_detection/core:box_coder",
"//tensorflow_models/object_detection/core:box_list", "//tensorflow/models/research/object_detection/core:box_list",
"//tensorflow_models/object_detection/core:standard_fields", "//tensorflow/models/research/object_detection/core:standard_fields",
], ],
) )
...@@ -50,8 +50,8 @@ py_test( ...@@ -50,8 +50,8 @@ py_test(
deps = [ deps = [
":keypoint_box_coder", ":keypoint_box_coder",
"//tensorflow", "//tensorflow",
"//tensorflow_models/object_detection/core:box_list", "//tensorflow/models/research/object_detection/core:box_list",
"//tensorflow_models/object_detection/core:standard_fields", "//tensorflow/models/research/object_detection/core:standard_fields",
], ],
) )
...@@ -61,8 +61,8 @@ py_library( ...@@ -61,8 +61,8 @@ py_library(
"mean_stddev_box_coder.py", "mean_stddev_box_coder.py",
], ],
deps = [ deps = [
"//tensorflow_models/object_detection/core:box_coder", "//tensorflow/models/research/object_detection/core:box_coder",
"//tensorflow_models/object_detection/core:box_list", "//tensorflow/models/research/object_detection/core:box_list",
], ],
) )
...@@ -74,7 +74,7 @@ py_test( ...@@ -74,7 +74,7 @@ py_test(
deps = [ deps = [
":mean_stddev_box_coder", ":mean_stddev_box_coder",
"//tensorflow", "//tensorflow",
"//tensorflow_models/object_detection/core:box_list", "//tensorflow/models/research/object_detection/core:box_list",
], ],
) )
...@@ -84,8 +84,8 @@ py_library( ...@@ -84,8 +84,8 @@ py_library(
"square_box_coder.py", "square_box_coder.py",
], ],
deps = [ deps = [
"//tensorflow_models/object_detection/core:box_coder", "//tensorflow/models/research/object_detection/core:box_coder",
"//tensorflow_models/object_detection/core:box_list", "//tensorflow/models/research/object_detection/core:box_list",
], ],
) )
...@@ -97,6 +97,6 @@ py_test( ...@@ -97,6 +97,6 @@ py_test(
deps = [ deps = [
":square_box_coder", ":square_box_coder",
"//tensorflow", "//tensorflow",
"//tensorflow_models/object_detection/core:box_list", "//tensorflow/models/research/object_detection/core:box_list",
], ],
) )
...@@ -20,18 +20,19 @@ py_library( ...@@ -20,18 +20,19 @@ py_library(
":matcher_builder", ":matcher_builder",
":post_processing_builder", ":post_processing_builder",
":region_similarity_calculator_builder", ":region_similarity_calculator_builder",
"//tensorflow_models/object_detection/core:box_predictor", "//tensorflow/models/research/object_detection/core:box_predictor",
"//tensorflow_models/object_detection/meta_architectures:faster_rcnn_meta_arch", "//tensorflow/models/research/object_detection/meta_architectures:faster_rcnn_meta_arch",
"//tensorflow_models/object_detection/meta_architectures:rfcn_meta_arch", "//tensorflow/models/research/object_detection/meta_architectures:rfcn_meta_arch",
"//tensorflow_models/object_detection/meta_architectures:ssd_meta_arch", "//tensorflow/models/research/object_detection/meta_architectures:ssd_meta_arch",
"//tensorflow_models/object_detection/models:embedded_ssd_mobilenet_v1_feature_extractor", "//tensorflow/models/research/object_detection/models:embedded_ssd_mobilenet_v1_feature_extractor",
"//tensorflow_models/object_detection/models:faster_rcnn_inception_resnet_v2_feature_extractor", "//tensorflow/models/research/object_detection/models:faster_rcnn_inception_resnet_v2_feature_extractor",
"//tensorflow_models/object_detection/models:faster_rcnn_inception_v2_feature_extractor", "//tensorflow/models/research/object_detection/models:faster_rcnn_inception_v2_feature_extractor",
"//tensorflow_models/object_detection/models:faster_rcnn_resnet_v1_feature_extractor", "//tensorflow/models/research/object_detection/models:faster_rcnn_nas_feature_extractor",
"//tensorflow_models/object_detection/models:ssd_inception_v2_feature_extractor", "//tensorflow/models/research/object_detection/models:faster_rcnn_resnet_v1_feature_extractor",
"//tensorflow_models/object_detection/models:ssd_inception_v3_feature_extractor", "//tensorflow/models/research/object_detection/models:ssd_inception_v2_feature_extractor",
"//tensorflow_models/object_detection/models:ssd_mobilenet_v1_feature_extractor", "//tensorflow/models/research/object_detection/models:ssd_inception_v3_feature_extractor",
"//tensorflow_models/object_detection/protos:model_py_pb2", "//tensorflow/models/research/object_detection/models:ssd_mobilenet_v1_feature_extractor",
"//tensorflow/models/research/object_detection/protos:model_py_pb2",
], ],
) )
...@@ -41,15 +42,16 @@ py_test( ...@@ -41,15 +42,16 @@ py_test(
deps = [ deps = [
":model_builder", ":model_builder",
"//tensorflow", "//tensorflow",
"//tensorflow_models/object_detection/meta_architectures:faster_rcnn_meta_arch", "//tensorflow/models/research/object_detection/meta_architectures:faster_rcnn_meta_arch",
"//tensorflow_models/object_detection/meta_architectures:ssd_meta_arch", "//tensorflow/models/research/object_detection/meta_architectures:ssd_meta_arch",
"//tensorflow_models/object_detection/models:faster_rcnn_inception_resnet_v2_feature_extractor", "//tensorflow/models/research/object_detection/models:faster_rcnn_inception_resnet_v2_feature_extractor",
"//tensorflow_models/object_detection/models:faster_rcnn_inception_v2_feature_extractor", "//tensorflow/models/research/object_detection/models:faster_rcnn_inception_v2_feature_extractor",
"//tensorflow_models/object_detection/models:faster_rcnn_resnet_v1_feature_extractor", "//tensorflow/models/research/object_detection/models:faster_rcnn_nas_feature_extractor",
"//tensorflow_models/object_detection/models:ssd_inception_v2_feature_extractor", "//tensorflow/models/research/object_detection/models:faster_rcnn_resnet_v1_feature_extractor",
"//tensorflow_models/object_detection/models:ssd_inception_v3_feature_extractor", "//tensorflow/models/research/object_detection/models:ssd_inception_v2_feature_extractor",
"//tensorflow_models/object_detection/models:ssd_mobilenet_v1_feature_extractor", "//tensorflow/models/research/object_detection/models:ssd_inception_v3_feature_extractor",
"//tensorflow_models/object_detection/protos:model_py_pb2", "//tensorflow/models/research/object_detection/models:ssd_mobilenet_v1_feature_extractor",
"//tensorflow/models/research/object_detection/protos:model_py_pb2",
], ],
) )
...@@ -57,9 +59,9 @@ py_library( ...@@ -57,9 +59,9 @@ py_library(
name = "matcher_builder", name = "matcher_builder",
srcs = ["matcher_builder.py"], srcs = ["matcher_builder.py"],
deps = [ deps = [
"//tensorflow_models/object_detection/matchers:argmax_matcher", "//tensorflow/models/research/object_detection/matchers:argmax_matcher",
"//tensorflow_models/object_detection/matchers:bipartite_matcher", "//tensorflow/models/research/object_detection/matchers:bipartite_matcher",
"//tensorflow_models/object_detection/protos:matcher_py_pb2", "//tensorflow/models/research/object_detection/protos:matcher_py_pb2",
], ],
) )
...@@ -68,9 +70,9 @@ py_test( ...@@ -68,9 +70,9 @@ py_test(
srcs = ["matcher_builder_test.py"], srcs = ["matcher_builder_test.py"],
deps = [ deps = [
":matcher_builder", ":matcher_builder",
"//tensorflow_models/object_detection/matchers:argmax_matcher", "//tensorflow/models/research/object_detection/matchers:argmax_matcher",
"//tensorflow_models/object_detection/matchers:bipartite_matcher", "//tensorflow/models/research/object_detection/matchers:bipartite_matcher",
"//tensorflow_models/object_detection/protos:matcher_py_pb2", "//tensorflow/models/research/object_detection/protos:matcher_py_pb2",
], ],
) )
...@@ -78,11 +80,11 @@ py_library( ...@@ -78,11 +80,11 @@ py_library(
name = "box_coder_builder", name = "box_coder_builder",
srcs = ["box_coder_builder.py"], srcs = ["box_coder_builder.py"],
deps = [ deps = [
"//tensorflow_models/object_detection/box_coders:faster_rcnn_box_coder", "//tensorflow/models/research/object_detection/box_coders:faster_rcnn_box_coder",
"//tensorflow_models/object_detection/box_coders:keypoint_box_coder", "//tensorflow/models/research/object_detection/box_coders:keypoint_box_coder",
"//tensorflow_models/object_detection/box_coders:mean_stddev_box_coder", "//tensorflow/models/research/object_detection/box_coders:mean_stddev_box_coder",
"//tensorflow_models/object_detection/box_coders:square_box_coder", "//tensorflow/models/research/object_detection/box_coders:square_box_coder",
"//tensorflow_models/object_detection/protos:box_coder_py_pb2", "//tensorflow/models/research/object_detection/protos:box_coder_py_pb2",
], ],
) )
...@@ -92,11 +94,11 @@ py_test( ...@@ -92,11 +94,11 @@ py_test(
deps = [ deps = [
":box_coder_builder", ":box_coder_builder",
"//tensorflow", "//tensorflow",
"//tensorflow_models/object_detection/box_coders:faster_rcnn_box_coder", "//tensorflow/models/research/object_detection/box_coders:faster_rcnn_box_coder",
"//tensorflow_models/object_detection/box_coders:keypoint_box_coder", "//tensorflow/models/research/object_detection/box_coders:keypoint_box_coder",
"//tensorflow_models/object_detection/box_coders:mean_stddev_box_coder", "//tensorflow/models/research/object_detection/box_coders:mean_stddev_box_coder",
"//tensorflow_models/object_detection/box_coders:square_box_coder", "//tensorflow/models/research/object_detection/box_coders:square_box_coder",
"//tensorflow_models/object_detection/protos:box_coder_py_pb2", "//tensorflow/models/research/object_detection/protos:box_coder_py_pb2",
], ],
) )
...@@ -104,9 +106,10 @@ py_library( ...@@ -104,9 +106,10 @@ py_library(
name = "anchor_generator_builder", name = "anchor_generator_builder",
srcs = ["anchor_generator_builder.py"], srcs = ["anchor_generator_builder.py"],
deps = [ deps = [
"//tensorflow_models/object_detection/anchor_generators:grid_anchor_generator", "//tensorflow/models/research/object_detection/anchor_generators:grid_anchor_generator",
"//tensorflow_models/object_detection/anchor_generators:multiple_grid_anchor_generator", "//tensorflow/models/research/object_detection/anchor_generators:multiple_grid_anchor_generator",
"//tensorflow_models/object_detection/protos:anchor_generator_py_pb2", "//tensorflow/models/research/object_detection/anchor_generators:multiscale_grid_anchor_generator",
"//tensorflow/models/research/object_detection/protos:anchor_generator_py_pb2",
], ],
) )
...@@ -116,9 +119,35 @@ py_test( ...@@ -116,9 +119,35 @@ py_test(
deps = [ deps = [
":anchor_generator_builder", ":anchor_generator_builder",
"//tensorflow", "//tensorflow",
"//tensorflow_models/object_detection/anchor_generators:grid_anchor_generator", "//tensorflow/models/research/object_detection/anchor_generators:grid_anchor_generator",
"//tensorflow_models/object_detection/anchor_generators:multiple_grid_anchor_generator", "//tensorflow/models/research/object_detection/anchor_generators:multiple_grid_anchor_generator",
"//tensorflow_models/object_detection/protos:anchor_generator_py_pb2", "//tensorflow/models/research/object_detection/anchor_generators:multiscale_grid_anchor_generator",
"//tensorflow/models/research/object_detection/protos:anchor_generator_py_pb2",
],
)
py_library(
name = "dataset_builder",
srcs = ["dataset_builder.py"],
deps = [
"//tensorflow",
"//tensorflow/models/research/object_detection/data_decoders:tf_example_decoder",
"//tensorflow/models/research/object_detection/protos:input_reader_py_pb2",
"//tensorflow/models/research/object_detection/utils:dataset_util",
],
)
py_test(
name = "dataset_builder_test",
srcs = [
"dataset_builder_test.py",
],
deps = [
":dataset_builder",
"//tensorflow",
"//tensorflow/models/research/object_detection/core:standard_fields",
"//tensorflow/models/research/object_detection/protos:input_reader_py_pb2",
"//tensorflow/models/research/object_detection/utils:dataset_util",
], ],
) )
...@@ -127,8 +156,8 @@ py_library( ...@@ -127,8 +156,8 @@ py_library(
srcs = ["input_reader_builder.py"], srcs = ["input_reader_builder.py"],
deps = [ deps = [
"//tensorflow", "//tensorflow",
"//tensorflow_models/object_detection/data_decoders:tf_example_decoder", "//tensorflow/models/research/object_detection/data_decoders:tf_example_decoder",
"//tensorflow_models/object_detection/protos:input_reader_py_pb2", "//tensorflow/models/research/object_detection/protos:input_reader_py_pb2",
], ],
) )
...@@ -140,8 +169,8 @@ py_test( ...@@ -140,8 +169,8 @@ py_test(
deps = [ deps = [
":input_reader_builder", ":input_reader_builder",
"//tensorflow", "//tensorflow",
"//tensorflow_models/object_detection/core:standard_fields", "//tensorflow/models/research/object_detection/core:standard_fields",
"//tensorflow_models/object_detection/protos:input_reader_py_pb2", "//tensorflow/models/research/object_detection/protos:input_reader_py_pb2",
], ],
) )
...@@ -149,8 +178,8 @@ py_library( ...@@ -149,8 +178,8 @@ py_library(
name = "losses_builder", name = "losses_builder",
srcs = ["losses_builder.py"], srcs = ["losses_builder.py"],
deps = [ deps = [
"//tensorflow_models/object_detection/core:losses", "//tensorflow/models/research/object_detection/core:losses",
"//tensorflow_models/object_detection/protos:losses_py_pb2", "//tensorflow/models/research/object_detection/protos:losses_py_pb2",
], ],
) )
...@@ -159,8 +188,8 @@ py_test( ...@@ -159,8 +188,8 @@ py_test(
srcs = ["losses_builder_test.py"], srcs = ["losses_builder_test.py"],
deps = [ deps = [
":losses_builder", ":losses_builder",
"//tensorflow_models/object_detection/core:losses", "//tensorflow/models/research/object_detection/core:losses",
"//tensorflow_models/object_detection/protos:losses_py_pb2", "//tensorflow/models/research/object_detection/protos:losses_py_pb2",
], ],
) )
...@@ -169,7 +198,7 @@ py_library( ...@@ -169,7 +198,7 @@ py_library(
srcs = ["optimizer_builder.py"], srcs = ["optimizer_builder.py"],
deps = [ deps = [
"//tensorflow", "//tensorflow",
"//tensorflow_models/object_detection/utils:learning_schedules", "//tensorflow/models/research/object_detection/utils:learning_schedules",
], ],
) )
...@@ -179,7 +208,7 @@ py_test( ...@@ -179,7 +208,7 @@ py_test(
deps = [ deps = [
":optimizer_builder", ":optimizer_builder",
"//tensorflow", "//tensorflow",
"//tensorflow_models/object_detection/protos:optimizer_py_pb2", "//tensorflow/models/research/object_detection/protos:optimizer_py_pb2",
], ],
) )
...@@ -188,8 +217,8 @@ py_library( ...@@ -188,8 +217,8 @@ py_library(
srcs = ["post_processing_builder.py"], srcs = ["post_processing_builder.py"],
deps = [ deps = [
"//tensorflow", "//tensorflow",
"//tensorflow_models/object_detection/core:post_processing", "//tensorflow/models/research/object_detection/core:post_processing",
"//tensorflow_models/object_detection/protos:post_processing_py_pb2", "//tensorflow/models/research/object_detection/protos:post_processing_py_pb2",
], ],
) )
...@@ -199,7 +228,7 @@ py_test( ...@@ -199,7 +228,7 @@ py_test(
deps = [ deps = [
":post_processing_builder", ":post_processing_builder",
"//tensorflow", "//tensorflow",
"//tensorflow_models/object_detection/protos:post_processing_py_pb2", "//tensorflow/models/research/object_detection/protos:post_processing_py_pb2",
], ],
) )
...@@ -207,7 +236,7 @@ py_library( ...@@ -207,7 +236,7 @@ py_library(
name = "hyperparams_builder", name = "hyperparams_builder",
srcs = ["hyperparams_builder.py"], srcs = ["hyperparams_builder.py"],
deps = [ deps = [
"//tensorflow_models/object_detection/protos:hyperparams_py_pb2", "//tensorflow/models/research/object_detection/protos:hyperparams_py_pb2",
], ],
) )
...@@ -217,7 +246,7 @@ py_test( ...@@ -217,7 +246,7 @@ py_test(
deps = [ deps = [
":hyperparams_builder", ":hyperparams_builder",
"//tensorflow", "//tensorflow",
"//tensorflow_models/object_detection/protos:hyperparams_py_pb2", "//tensorflow/models/research/object_detection/protos:hyperparams_py_pb2",
], ],
) )
...@@ -226,8 +255,8 @@ py_library( ...@@ -226,8 +255,8 @@ py_library(
srcs = ["box_predictor_builder.py"], srcs = ["box_predictor_builder.py"],
deps = [ deps = [
":hyperparams_builder", ":hyperparams_builder",
"//tensorflow_models/object_detection/core:box_predictor", "//tensorflow/models/research/object_detection/core:box_predictor",
"//tensorflow_models/object_detection/protos:box_predictor_py_pb2", "//tensorflow/models/research/object_detection/protos:box_predictor_py_pb2",
], ],
) )
...@@ -238,8 +267,8 @@ py_test( ...@@ -238,8 +267,8 @@ py_test(
":box_predictor_builder", ":box_predictor_builder",
":hyperparams_builder", ":hyperparams_builder",
"//tensorflow", "//tensorflow",
"//tensorflow_models/object_detection/protos:box_predictor_py_pb2", "//tensorflow/models/research/object_detection/protos:box_predictor_py_pb2",
"//tensorflow_models/object_detection/protos:hyperparams_py_pb2", "//tensorflow/models/research/object_detection/protos:hyperparams_py_pb2",
], ],
) )
...@@ -247,8 +276,8 @@ py_library( ...@@ -247,8 +276,8 @@ py_library(
name = "region_similarity_calculator_builder", name = "region_similarity_calculator_builder",
srcs = ["region_similarity_calculator_builder.py"], srcs = ["region_similarity_calculator_builder.py"],
deps = [ deps = [
"//tensorflow_models/object_detection/core:region_similarity_calculator", "//tensorflow/models/research/object_detection/core:region_similarity_calculator",
"//tensorflow_models/object_detection/protos:region_similarity_calculator_py_pb2", "//tensorflow/models/research/object_detection/protos:region_similarity_calculator_py_pb2",
], ],
) )
...@@ -266,8 +295,8 @@ py_library( ...@@ -266,8 +295,8 @@ py_library(
srcs = ["preprocessor_builder.py"], srcs = ["preprocessor_builder.py"],
deps = [ deps = [
"//tensorflow", "//tensorflow",
"//tensorflow_models/object_detection/core:preprocessor", "//tensorflow/models/research/object_detection/core:preprocessor",
"//tensorflow_models/object_detection/protos:preprocessor_py_pb2", "//tensorflow/models/research/object_detection/protos:preprocessor_py_pb2",
], ],
) )
...@@ -279,8 +308,8 @@ py_test( ...@@ -279,8 +308,8 @@ py_test(
deps = [ deps = [
":preprocessor_builder", ":preprocessor_builder",
"//tensorflow", "//tensorflow",
"//tensorflow_models/object_detection/core:preprocessor", "//tensorflow/models/research/object_detection/core:preprocessor",
"//tensorflow_models/object_detection/protos:preprocessor_py_pb2", "//tensorflow/models/research/object_detection/protos:preprocessor_py_pb2",
], ],
) )
...@@ -289,8 +318,8 @@ py_library( ...@@ -289,8 +318,8 @@ py_library(
srcs = ["image_resizer_builder.py"], srcs = ["image_resizer_builder.py"],
deps = [ deps = [
"//tensorflow", "//tensorflow",
"//tensorflow_models/object_detection/core:preprocessor", "//tensorflow/models/research/object_detection/core:preprocessor",
"//tensorflow_models/object_detection/protos:image_resizer_py_pb2", "//tensorflow/models/research/object_detection/protos:image_resizer_py_pb2",
], ],
) )
...@@ -300,6 +329,6 @@ py_test( ...@@ -300,6 +329,6 @@ py_test(
deps = [ deps = [
":image_resizer_builder", ":image_resizer_builder",
"//tensorflow", "//tensorflow",
"//tensorflow_models/object_detection/protos:image_resizer_py_pb2", "//tensorflow/models/research/object_detection/protos:image_resizer_py_pb2",
], ],
) )
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
from object_detection.anchor_generators import grid_anchor_generator from object_detection.anchor_generators import grid_anchor_generator
from object_detection.anchor_generators import multiple_grid_anchor_generator from object_detection.anchor_generators import multiple_grid_anchor_generator
from object_detection.anchor_generators import multiscale_grid_anchor_generator
from object_detection.protos import anchor_generator_pb2 from object_detection.protos import anchor_generator_pb2
...@@ -78,5 +79,15 @@ def build(anchor_generator_config): ...@@ -78,5 +79,15 @@ def build(anchor_generator_config):
anchor_offsets=anchor_offsets, anchor_offsets=anchor_offsets,
reduce_boxes_in_lowest_layer=( reduce_boxes_in_lowest_layer=(
ssd_anchor_generator_config.reduce_boxes_in_lowest_layer)) ssd_anchor_generator_config.reduce_boxes_in_lowest_layer))
elif anchor_generator_config.WhichOneof(
'anchor_generator_oneof') == 'multiscale_anchor_generator':
cfg = anchor_generator_config.multiscale_anchor_generator
return multiscale_grid_anchor_generator.MultiscaleGridAnchorGenerator(
cfg.min_lvl,
cfg.max_lvl,
cfg.anchor_scale,
cfg.aspect_ratios,
cfg.scales_per_octave
)
else: else:
raise ValueError('Empty anchor generator.') raise ValueError('Empty anchor generator.')
...@@ -68,6 +68,24 @@ def build(argscope_fn, box_predictor_config, is_training, num_classes): ...@@ -68,6 +68,24 @@ def build(argscope_fn, box_predictor_config, is_training, num_classes):
) )
return box_predictor_object return box_predictor_object
if box_predictor_oneof == 'weight_shared_convolutional_box_predictor':
conv_box_predictor = (box_predictor_config.
weight_shared_convolutional_box_predictor)
conv_hyperparams = argscope_fn(conv_box_predictor.conv_hyperparams,
is_training)
box_predictor_object = box_predictor.WeightSharedConvolutionalBoxPredictor(
is_training=is_training,
num_classes=num_classes,
conv_hyperparams=conv_hyperparams,
depth=conv_box_predictor.depth,
num_layers_before_predictor=(conv_box_predictor.
num_layers_before_predictor),
kernel_size=conv_box_predictor.kernel_size,
box_code_size=conv_box_predictor.box_code_size,
class_prediction_bias_init=conv_box_predictor.class_prediction_bias_init
)
return box_predictor_object
if box_predictor_oneof == 'mask_rcnn_box_predictor': if box_predictor_oneof == 'mask_rcnn_box_predictor':
mask_rcnn_box_predictor = box_predictor_config.mask_rcnn_box_predictor mask_rcnn_box_predictor = box_predictor_config.mask_rcnn_box_predictor
fc_hyperparams = argscope_fn(mask_rcnn_box_predictor.fc_hyperparams, fc_hyperparams = argscope_fn(mask_rcnn_box_predictor.fc_hyperparams,
...@@ -85,8 +103,12 @@ def build(argscope_fn, box_predictor_config, is_training, num_classes): ...@@ -85,8 +103,12 @@ def build(argscope_fn, box_predictor_config, is_training, num_classes):
box_code_size=mask_rcnn_box_predictor.box_code_size, box_code_size=mask_rcnn_box_predictor.box_code_size,
conv_hyperparams=conv_hyperparams, conv_hyperparams=conv_hyperparams,
predict_instance_masks=mask_rcnn_box_predictor.predict_instance_masks, predict_instance_masks=mask_rcnn_box_predictor.predict_instance_masks,
mask_prediction_conv_depth=(mask_rcnn_box_predictor. mask_height=mask_rcnn_box_predictor.mask_height,
mask_prediction_conv_depth), mask_width=mask_rcnn_box_predictor.mask_width,
mask_prediction_num_conv_layers=(
mask_rcnn_box_predictor.mask_prediction_num_conv_layers),
mask_prediction_conv_depth=(
mask_rcnn_box_predictor.mask_prediction_conv_depth),
predict_keypoints=mask_rcnn_box_predictor.predict_keypoints) predict_keypoints=mask_rcnn_box_predictor.predict_keypoints)
return box_predictor_object return box_predictor_object
......
...@@ -150,6 +150,120 @@ class ConvolutionalBoxPredictorBuilderTest(tf.test.TestCase): ...@@ -150,6 +150,120 @@ class ConvolutionalBoxPredictorBuilderTest(tf.test.TestCase):
self.assertTrue(box_predictor._is_training) self.assertTrue(box_predictor._is_training)
class WeightSharedConvolutionalBoxPredictorBuilderTest(tf.test.TestCase):
def test_box_predictor_calls_conv_argscope_fn(self):
conv_hyperparams_text_proto = """
regularizer {
l1_regularizer {
weight: 0.0003
}
}
initializer {
truncated_normal_initializer {
mean: 0.0
stddev: 0.3
}
}
activation: RELU_6
"""
hyperparams_proto = hyperparams_pb2.Hyperparams()
text_format.Merge(conv_hyperparams_text_proto, hyperparams_proto)
def mock_conv_argscope_builder(conv_hyperparams_arg, is_training):
return (conv_hyperparams_arg, is_training)
box_predictor_proto = box_predictor_pb2.BoxPredictor()
(box_predictor_proto.weight_shared_convolutional_box_predictor
.conv_hyperparams.CopyFrom(hyperparams_proto))
box_predictor = box_predictor_builder.build(
argscope_fn=mock_conv_argscope_builder,
box_predictor_config=box_predictor_proto,
is_training=False,
num_classes=10)
(conv_hyperparams_actual, is_training) = box_predictor._conv_hyperparams
self.assertAlmostEqual((hyperparams_proto.regularizer.
l1_regularizer.weight),
(conv_hyperparams_actual.regularizer.l1_regularizer.
weight))
self.assertAlmostEqual((hyperparams_proto.initializer.
truncated_normal_initializer.stddev),
(conv_hyperparams_actual.initializer.
truncated_normal_initializer.stddev))
self.assertAlmostEqual((hyperparams_proto.initializer.
truncated_normal_initializer.mean),
(conv_hyperparams_actual.initializer.
truncated_normal_initializer.mean))
self.assertEqual(hyperparams_proto.activation,
conv_hyperparams_actual.activation)
self.assertFalse(is_training)
def test_construct_non_default_conv_box_predictor(self):
box_predictor_text_proto = """
weight_shared_convolutional_box_predictor {
depth: 2
num_layers_before_predictor: 2
kernel_size: 7
box_code_size: 3
class_prediction_bias_init: 4.0
}
"""
conv_hyperparams_text_proto = """
regularizer {
l1_regularizer {
}
}
initializer {
truncated_normal_initializer {
}
}
"""
hyperparams_proto = hyperparams_pb2.Hyperparams()
text_format.Merge(conv_hyperparams_text_proto, hyperparams_proto)
def mock_conv_argscope_builder(conv_hyperparams_arg, is_training):
return (conv_hyperparams_arg, is_training)
box_predictor_proto = box_predictor_pb2.BoxPredictor()
text_format.Merge(box_predictor_text_proto, box_predictor_proto)
(box_predictor_proto.weight_shared_convolutional_box_predictor.
conv_hyperparams.CopyFrom(hyperparams_proto))
box_predictor = box_predictor_builder.build(
argscope_fn=mock_conv_argscope_builder,
box_predictor_config=box_predictor_proto,
is_training=False,
num_classes=10)
self.assertEqual(box_predictor._depth, 2)
self.assertEqual(box_predictor._num_layers_before_predictor, 2)
self.assertAlmostEqual(box_predictor._class_prediction_bias_init, 4.0)
self.assertEqual(box_predictor.num_classes, 10)
self.assertFalse(box_predictor._is_training)
def test_construct_default_conv_box_predictor(self):
box_predictor_text_proto = """
weight_shared_convolutional_box_predictor {
conv_hyperparams {
regularizer {
l1_regularizer {
}
}
initializer {
truncated_normal_initializer {
}
}
}
}"""
box_predictor_proto = box_predictor_pb2.BoxPredictor()
text_format.Merge(box_predictor_text_proto, box_predictor_proto)
box_predictor = box_predictor_builder.build(
argscope_fn=hyperparams_builder.build,
box_predictor_config=box_predictor_proto,
is_training=True,
num_classes=90)
self.assertEqual(box_predictor._depth, 0)
self.assertEqual(box_predictor._num_layers_before_predictor, 0)
self.assertEqual(box_predictor.num_classes, 90)
self.assertTrue(box_predictor._is_training)
class MaskRCNNBoxPredictorBuilderTest(tf.test.TestCase): class MaskRCNNBoxPredictorBuilderTest(tf.test.TestCase):
def test_box_predictor_builder_calls_fc_argscope_fn(self): def test_box_predictor_builder_calls_fc_argscope_fn(self):
...@@ -247,6 +361,8 @@ class MaskRCNNBoxPredictorBuilderTest(tf.test.TestCase): ...@@ -247,6 +361,8 @@ class MaskRCNNBoxPredictorBuilderTest(tf.test.TestCase):
hyperparams_pb2.Hyperparams.CONV) hyperparams_pb2.Hyperparams.CONV)
box_predictor_proto.mask_rcnn_box_predictor.predict_instance_masks = True box_predictor_proto.mask_rcnn_box_predictor.predict_instance_masks = True
box_predictor_proto.mask_rcnn_box_predictor.mask_prediction_conv_depth = 512 box_predictor_proto.mask_rcnn_box_predictor.mask_prediction_conv_depth = 512
box_predictor_proto.mask_rcnn_box_predictor.mask_height = 16
box_predictor_proto.mask_rcnn_box_predictor.mask_width = 16
mock_argscope_fn = mock.Mock(return_value='arg_scope') mock_argscope_fn = mock.Mock(return_value='arg_scope')
box_predictor = box_predictor_builder.build( box_predictor = box_predictor_builder.build(
argscope_fn=mock_argscope_fn, argscope_fn=mock_argscope_fn,
......
# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""tf.data.Dataset builder.
Creates data sources for DetectionModels from an InputReader config. See
input_reader.proto for options.
Note: If users wishes to also use their own InputReaders with the Object
Detection configuration framework, they should define their own builder function
that wraps the build function.
"""
import tensorflow as tf
from object_detection.data_decoders import tf_example_decoder
from object_detection.protos import input_reader_pb2
from object_detection.utils import dataset_util
def build(input_reader_config, num_workers=1, worker_index=0):
"""Builds a tf.data.Dataset based on the InputReader config.
Args:
input_reader_config: A input_reader_pb2.InputReader object.
num_workers: Number of workers / shards.
worker_index: Id for the current worker.
Returns:
A tf.data.Dataset based on the input_reader_config.
Raises:
ValueError: On invalid input reader proto.
ValueError: If no input paths are specified.
"""
if not isinstance(input_reader_config, input_reader_pb2.InputReader):
raise ValueError('input_reader_config not of type '
'input_reader_pb2.InputReader.')
if input_reader_config.WhichOneof('input_reader') == 'tf_record_input_reader':
config = input_reader_config.tf_record_input_reader
if not config.input_path:
raise ValueError('At least one input path must be specified in '
'`input_reader_config`.')
label_map_proto_file = None
if input_reader_config.HasField('label_map_path'):
label_map_proto_file = input_reader_config.label_map_path
decoder = tf_example_decoder.TfExampleDecoder(
load_instance_masks=input_reader_config.load_instance_masks,
instance_mask_type=input_reader_config.mask_type,
label_map_proto_file=label_map_proto_file)
return dataset_util.read_dataset(
tf.data.TFRecordDataset, decoder.decode, config.input_path[:],
input_reader_config, num_workers, worker_index)
raise ValueError('Unsupported input_reader_config.')
# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Tests for dataset_builder."""
import os
import numpy as np
import tensorflow as tf
from google.protobuf import text_format
from tensorflow.core.example import example_pb2
from tensorflow.core.example import feature_pb2
from object_detection.builders import dataset_builder
from object_detection.core import standard_fields as fields
from object_detection.protos import input_reader_pb2
from object_detection.utils import dataset_util
class DatasetBuilderTest(tf.test.TestCase):
def create_tf_record(self):
path = os.path.join(self.get_temp_dir(), 'tfrecord')
writer = tf.python_io.TFRecordWriter(path)
image_tensor = np.random.randint(255, size=(4, 5, 3)).astype(np.uint8)
flat_mask = (4 * 5) * [1.0]
with self.test_session():
encoded_jpeg = tf.image.encode_jpeg(tf.constant(image_tensor)).eval()
example = example_pb2.Example(
features=feature_pb2.Features(
feature={
'image/encoded':
feature_pb2.Feature(
bytes_list=feature_pb2.BytesList(value=[encoded_jpeg])),
'image/format':
feature_pb2.Feature(
bytes_list=feature_pb2.BytesList(
value=['jpeg'.encode('utf-8')])),
'image/height':
feature_pb2.Feature(
int64_list=feature_pb2.Int64List(value=[4])),
'image/width':
feature_pb2.Feature(
int64_list=feature_pb2.Int64List(value=[5])),
'image/object/bbox/xmin':
feature_pb2.Feature(
float_list=feature_pb2.FloatList(value=[0.0])),
'image/object/bbox/xmax':
feature_pb2.Feature(
float_list=feature_pb2.FloatList(value=[1.0])),
'image/object/bbox/ymin':
feature_pb2.Feature(
float_list=feature_pb2.FloatList(value=[0.0])),
'image/object/bbox/ymax':
feature_pb2.Feature(
float_list=feature_pb2.FloatList(value=[1.0])),
'image/object/class/label':
feature_pb2.Feature(
int64_list=feature_pb2.Int64List(value=[2])),
'image/object/mask':
feature_pb2.Feature(
float_list=feature_pb2.FloatList(value=flat_mask)),
}))
writer.write(example.SerializeToString())
writer.close()
return path
def test_build_tf_record_input_reader(self):
tf_record_path = self.create_tf_record()
input_reader_text_proto = """
shuffle: false
num_readers: 1
tf_record_input_reader {{
input_path: '{0}'
}}
""".format(tf_record_path)
input_reader_proto = input_reader_pb2.InputReader()
text_format.Merge(input_reader_text_proto, input_reader_proto)
tensor_dict = dataset_util.make_initializable_iterator(
dataset_builder.build(input_reader_proto)).get_next()
sv = tf.train.Supervisor(logdir=self.get_temp_dir())
with sv.prepare_or_wait_for_session() as sess:
sv.start_queue_runners(sess)
output_dict = sess.run(tensor_dict)
self.assertTrue(
fields.InputDataFields.groundtruth_instance_masks not in output_dict)
self.assertEquals((4, 5, 3),
output_dict[fields.InputDataFields.image].shape)
self.assertEquals([2],
output_dict[fields.InputDataFields.groundtruth_classes])
self.assertEquals(
(1, 4), output_dict[fields.InputDataFields.groundtruth_boxes].shape)
self.assertAllEqual(
[0.0, 0.0, 1.0, 1.0],
output_dict[fields.InputDataFields.groundtruth_boxes][0])
def test_build_tf_record_input_reader_and_load_instance_masks(self):
tf_record_path = self.create_tf_record()
input_reader_text_proto = """
shuffle: false
num_readers: 1
load_instance_masks: true
tf_record_input_reader {{
input_path: '{0}'
}}
""".format(tf_record_path)
input_reader_proto = input_reader_pb2.InputReader()
text_format.Merge(input_reader_text_proto, input_reader_proto)
tensor_dict = dataset_util.make_initializable_iterator(
dataset_builder.build(input_reader_proto)).get_next()
sv = tf.train.Supervisor(logdir=self.get_temp_dir())
with sv.prepare_or_wait_for_session() as sess:
sv.start_queue_runners(sess)
output_dict = sess.run(tensor_dict)
self.assertEquals((4, 5, 3),
output_dict[fields.InputDataFields.image].shape)
self.assertEquals([2],
output_dict[fields.InputDataFields.groundtruth_classes])
self.assertEquals(
(1, 4), output_dict[fields.InputDataFields.groundtruth_boxes].shape)
self.assertAllEqual(
[0.0, 0.0, 1.0, 1.0],
output_dict[fields.InputDataFields.groundtruth_boxes][0])
self.assertAllEqual(
(1, 4, 5),
output_dict[fields.InputDataFields.groundtruth_instance_masks].shape)
def test_raises_error_with_no_input_paths(self):
input_reader_text_proto = """
shuffle: false
num_readers: 1
load_instance_masks: true
"""
input_reader_proto = input_reader_pb2.InputReader()
text_format.Merge(input_reader_text_proto, input_reader_proto)
with self.assertRaises(ValueError):
dataset_builder.build(input_reader_proto)
if __name__ == '__main__':
tf.test.main()
...@@ -83,7 +83,8 @@ def build(image_resizer_config): ...@@ -83,7 +83,8 @@ def build(image_resizer_config):
preprocessor.resize_to_range, preprocessor.resize_to_range,
min_dimension=keep_aspect_ratio_config.min_dimension, min_dimension=keep_aspect_ratio_config.min_dimension,
max_dimension=keep_aspect_ratio_config.max_dimension, max_dimension=keep_aspect_ratio_config.max_dimension,
method=method) method=method,
pad_to_max_dimension=keep_aspect_ratio_config.pad_to_max_dimension)
if image_resizer_config.WhichOneof( if image_resizer_config.WhichOneof(
'image_resizer_oneof') == 'fixed_shape_resizer': 'image_resizer_oneof') == 'fixed_shape_resizer':
fixed_shape_resizer_config = image_resizer_config.fixed_shape_resizer fixed_shape_resizer_config = image_resizer_config.fixed_shape_resizer
......
...@@ -29,11 +29,11 @@ class ImageResizerBuilderTest(tf.test.TestCase): ...@@ -29,11 +29,11 @@ class ImageResizerBuilderTest(tf.test.TestCase):
image_resizer_fn = image_resizer_builder.build(image_resizer_config) image_resizer_fn = image_resizer_builder.build(image_resizer_config)
images = tf.to_float( images = tf.to_float(
tf.random_uniform(input_shape, minval=0, maxval=255, dtype=tf.int32)) tf.random_uniform(input_shape, minval=0, maxval=255, dtype=tf.int32))
resized_images = image_resizer_fn(images) resized_images, _ = image_resizer_fn(images)
with self.test_session() as sess: with self.test_session() as sess:
return sess.run(resized_images).shape return sess.run(resized_images).shape
def test_built_keep_aspect_ratio_resizer_returns_expected_shape(self): def test_build_keep_aspect_ratio_resizer_returns_expected_shape(self):
image_resizer_text_proto = """ image_resizer_text_proto = """
keep_aspect_ratio_resizer { keep_aspect_ratio_resizer {
min_dimension: 10 min_dimension: 10
...@@ -46,6 +46,20 @@ class ImageResizerBuilderTest(tf.test.TestCase): ...@@ -46,6 +46,20 @@ class ImageResizerBuilderTest(tf.test.TestCase):
input_shape, image_resizer_text_proto) input_shape, image_resizer_text_proto)
self.assertEqual(output_shape, expected_output_shape) self.assertEqual(output_shape, expected_output_shape)
def test_build_keep_aspect_ratio_resizer_with_padding(self):
image_resizer_text_proto = """
keep_aspect_ratio_resizer {
min_dimension: 10
max_dimension: 20
pad_to_max_dimension: true
}
"""
input_shape = (50, 25, 3)
expected_output_shape = (20, 20, 3)
output_shape = self._shape_of_resized_random_image_given_text_proto(
input_shape, image_resizer_text_proto)
self.assertEqual(output_shape, expected_output_shape)
def test_built_fixed_shape_resizer_returns_expected_shape(self): def test_built_fixed_shape_resizer_returns_expected_shape(self):
image_resizer_text_proto = """ image_resizer_text_proto = """
fixed_shape_resizer { fixed_shape_resizer {
...@@ -69,7 +83,7 @@ class ImageResizerBuilderTest(tf.test.TestCase): ...@@ -69,7 +83,7 @@ class ImageResizerBuilderTest(tf.test.TestCase):
text_format.Merge(text_proto, image_resizer_config) text_format.Merge(text_proto, image_resizer_config)
image_resizer_fn = image_resizer_builder.build(image_resizer_config) image_resizer_fn = image_resizer_builder.build(image_resizer_config)
image_placeholder = tf.placeholder(tf.uint8, [1, None, None, 3]) image_placeholder = tf.placeholder(tf.uint8, [1, None, None, 3])
resized_image = image_resizer_fn(image_placeholder) resized_image, _ = image_resizer_fn(image_placeholder)
with self.test_session() as sess: with self.test_session() as sess:
return sess.run(resized_image, feed_dict={image_placeholder: image}) return sess.run(resized_image, feed_dict={image_placeholder: image})
......
...@@ -69,6 +69,7 @@ def build(input_reader_config): ...@@ -69,6 +69,7 @@ def build(input_reader_config):
label_map_proto_file = input_reader_config.label_map_path label_map_proto_file = input_reader_config.label_map_path
decoder = tf_example_decoder.TfExampleDecoder( decoder = tf_example_decoder.TfExampleDecoder(
load_instance_masks=input_reader_config.load_instance_masks, load_instance_masks=input_reader_config.load_instance_masks,
instance_mask_type=input_reader_config.mask_type,
label_map_proto_file=label_map_proto_file) label_map_proto_file=label_map_proto_file)
return decoder.decode(string_tensor) return decoder.decode(string_tensor)
......
...@@ -116,18 +116,17 @@ def build_faster_rcnn_classification_loss(loss_config): ...@@ -116,18 +116,17 @@ def build_faster_rcnn_classification_loss(loss_config):
loss_type = loss_config.WhichOneof('classification_loss') loss_type = loss_config.WhichOneof('classification_loss')
if loss_type == 'weighted_sigmoid': if loss_type == 'weighted_sigmoid':
config = loss_config.weighted_sigmoid return losses.WeightedSigmoidClassificationLoss()
return losses.WeightedSigmoidClassificationLoss(
anchorwise_output=config.anchorwise_output)
if loss_type == 'weighted_softmax': if loss_type == 'weighted_softmax':
config = loss_config.weighted_softmax config = loss_config.weighted_softmax
return losses.WeightedSoftmaxClassificationLoss( return losses.WeightedSoftmaxClassificationLoss(
anchorwise_output=config.anchorwise_output) logit_scale=config.logit_scale)
# By default, Faster RCNN second stage classifier uses Softmax loss # By default, Faster RCNN second stage classifier uses Softmax loss
# with anchor-wise outputs. # with anchor-wise outputs.
config = loss_config.weighted_softmax
return losses.WeightedSoftmaxClassificationLoss( return losses.WeightedSoftmaxClassificationLoss(
anchorwise_output=True) logit_scale=config.logit_scale)
def _build_localization_loss(loss_config): def _build_localization_loss(loss_config):
...@@ -148,14 +147,10 @@ def _build_localization_loss(loss_config): ...@@ -148,14 +147,10 @@ def _build_localization_loss(loss_config):
loss_type = loss_config.WhichOneof('localization_loss') loss_type = loss_config.WhichOneof('localization_loss')
if loss_type == 'weighted_l2': if loss_type == 'weighted_l2':
config = loss_config.weighted_l2 return losses.WeightedL2LocalizationLoss()
return losses.WeightedL2LocalizationLoss(
anchorwise_output=config.anchorwise_output)
if loss_type == 'weighted_smooth_l1': if loss_type == 'weighted_smooth_l1':
config = loss_config.weighted_smooth_l1 return losses.WeightedSmoothL1LocalizationLoss()
return losses.WeightedSmoothL1LocalizationLoss(
anchorwise_output=config.anchorwise_output)
if loss_type == 'weighted_iou': if loss_type == 'weighted_iou':
return losses.WeightedIOULocalizationLoss() return losses.WeightedIOULocalizationLoss()
...@@ -181,9 +176,7 @@ def _build_classification_loss(loss_config): ...@@ -181,9 +176,7 @@ def _build_classification_loss(loss_config):
loss_type = loss_config.WhichOneof('classification_loss') loss_type = loss_config.WhichOneof('classification_loss')
if loss_type == 'weighted_sigmoid': if loss_type == 'weighted_sigmoid':
config = loss_config.weighted_sigmoid return losses.WeightedSigmoidClassificationLoss()
return losses.WeightedSigmoidClassificationLoss(
anchorwise_output=config.anchorwise_output)
if loss_type == 'weighted_sigmoid_focal': if loss_type == 'weighted_sigmoid_focal':
config = loss_config.weighted_sigmoid_focal config = loss_config.weighted_sigmoid_focal
...@@ -191,21 +184,18 @@ def _build_classification_loss(loss_config): ...@@ -191,21 +184,18 @@ def _build_classification_loss(loss_config):
if config.HasField('alpha'): if config.HasField('alpha'):
alpha = config.alpha alpha = config.alpha
return losses.SigmoidFocalClassificationLoss( return losses.SigmoidFocalClassificationLoss(
anchorwise_output=config.anchorwise_output,
gamma=config.gamma, gamma=config.gamma,
alpha=alpha) alpha=alpha)
if loss_type == 'weighted_softmax': if loss_type == 'weighted_softmax':
config = loss_config.weighted_softmax config = loss_config.weighted_softmax
return losses.WeightedSoftmaxClassificationLoss( return losses.WeightedSoftmaxClassificationLoss(
anchorwise_output=config.anchorwise_output,
logit_scale=config.logit_scale) logit_scale=config.logit_scale)
if loss_type == 'bootstrapped_sigmoid': if loss_type == 'bootstrapped_sigmoid':
config = loss_config.bootstrapped_sigmoid config = loss_config.bootstrapped_sigmoid
return losses.BootstrappedSigmoidClassificationLoss( return losses.BootstrappedSigmoidClassificationLoss(
alpha=config.alpha, alpha=config.alpha,
bootstrap_type=('hard' if config.hard_bootstrap else 'soft'), bootstrap_type=('hard' if config.hard_bootstrap else 'soft'))
anchorwise_output=config.anchorwise_output)
raise ValueError('Empty loss config.') raise ValueError('Empty loss config.')
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment