def getDimensionsFromModelId(modelId, modelInfoFilename, modelCatFilename): modelInfo = ModelInformation(modelInfoFilename) modelCat = ModelCategoryMapping(modelCatFilename) refModelDimensions = None otherSimilarDimensions = [] refModelId = str(modelId) refCategory = modelCat.getCoarseGrainedCategoryForModelId(refModelId) for modelId in modelInfo.model_info.keys(): category = modelCat.getCoarseGrainedCategoryForModelId(modelId) if refCategory == category: info = modelInfo.getModelInfo(modelId) # FIXME: handle the general case where for the front vector, do not ignore # NOTE: SUNCG is using the Y-up coordinate system frontVec = info['front'] if np.count_nonzero(frontVec) > 1 or not np.array_equal( frontVec, [0, 0, 1]): continue width, height, depth = info['aligned_dims'] / 100.0 # cm to m otherSimilarDimensions.append([width, height, depth]) if refModelId == modelId: refModelDimensions = np.array([width, height, depth]) otherSimilarDimensions = np.array(otherSimilarDimensions) logger.debug('Number of similar objects found in dataset: %d' % (otherSimilarDimensions.shape[0])) # Volume statistics (assume a gaussian distribution) # XXX: use a more general histogram method to define the categories, # rather than simply comparing the deviation to the mean refVolume = np.prod(refModelDimensions) otherVolumes = np.prod(otherSimilarDimensions, axis=-1) mean = np.mean(otherVolumes) std = np.std(otherVolumes) # Compare the deviation to the mean overallSizeTag = None diff = refVolume - mean for tag, threshold in DimensionTable.overallSizeTable: if threshold >= 0.0: if diff > threshold * std: overallSizeTag = tag else: if diff < threshold * std: overallSizeTag = tag if overallSizeTag is None: overallSizeTag = 'normal' return overallSizeTag
def testGetModelInfo(self): info = ModelInformation( os.path.join(TEST_SUNCG_DATA_DIR, "metadata", "models.csv")) _ = info.getModelInfo('261')
def testInit(self): _ = ModelInformation( os.path.join(TEST_SUNCG_DATA_DIR, "metadata", "models.csv"))