Skip to content

Commit 88316c4

Browse files
authored
Merge pull request #28 from DigitalSlideArchive/27-update-feature-h5-and-superpixel-tiff-filenames
27 update feature h5 and superpixel tiff filenames
2 parents 5d12e4f + 2246832 commit 88316c4

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

superpixel_classification/SuperpixelClassification/SuperpixelClassificationBase.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def progCallback(step, count, total):
204204
print('Create superpixels for %s' % item['name'])
205205
imagePath = os.path.join(tempdir, item['name'])
206206
gc.downloadFile(item['largeImage']['fileId'], imagePath)
207-
outImagePath = os.path.join(tempdir, 'superpixel.tiff')
207+
outImagePath = os.path.join(tempdir, '%s.pixelmap.tiff' % item['name'])
208208
outAnnotationPath = os.path.join(tempdir, '%s.anot' % annotationName)
209209

210210
if True:
@@ -426,22 +426,30 @@ def createFeatures(self, gc, folderId, annotationName, featureFolderId, patchSiz
426426
prog.items([item for item, _, _ in itemsAndAnnot])
427427
results = {}
428428
futures = []
429+
featureFiles = [
430+
f for item in gc.listItem(featureFolderId) for f in gc.listFile(item['_id'])
431+
]
429432
with concurrent.futures.ThreadPoolExecutor(max_workers=numWorkers) as executor:
430433
for item, _, elem in itemsAndAnnot:
431-
bbox = elem['user']['bbox']
432-
hashval = repr(dict(
433-
itemId=item['_id'], bbox=[int(v) for v in bbox], patchSize=patchSize))
434-
hashval = hashlib.new('sha256', hashval.encode()).hexdigest()
435-
fileName = 'feature-%s.h5' % (hashval)
436-
found = False
437-
for existing in gc.listItem(featureFolderId, name=fileName):
438-
results[item['_id']] = next(gc.listFile(existing['_id'], limit=1))
439-
found = True
440-
break
441-
if not found:
442-
futures.append((item, executor.submit(
443-
self.createFeaturesForItem, gc, item, elem, featureFolderId, fileName,
444-
patchSize, prog)))
434+
match = [
435+
f for f in featureFiles if
436+
re.match('^%s.*[.]feature.h5$' % re.escape(item['name']), f['name'])
437+
]
438+
if len(match):
439+
results[item['_id']] = match[0]
440+
else: # fallback to hash-based naming - generate features if necessary
441+
bbox = elem['user']['bbox']
442+
hashval = repr(dict(
443+
itemId=item['_id'], bbox=[int(v) for v in bbox], patchSize=patchSize))
444+
hashval = hashlib.new('sha256', hashval.encode()).hexdigest()
445+
fileName = 'feature-%s.h5' % (hashval)
446+
match = [f for f in featureFiles if f['name'] == fileName]
447+
if len(match):
448+
results[item['_id']] = match[0]
449+
else:
450+
futures.append((item, executor.submit(
451+
self.createFeaturesForItem, gc, item, elem, featureFolderId,
452+
'%s.feature.h5' % (item['name']), patchSize, prog)))
445453
for item, future in futures:
446454
file = future.result()
447455
try:

0 commit comments

Comments
 (0)