vislearnlabpy 0.0.3.0__tar.gz → 0.0.3.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (24) hide show
  1. {vislearnlabpy-0.0.3.0/src/vislearnlabpy.egg-info → vislearnlabpy-0.0.3.2}/PKG-INFO +1 -1
  2. {vislearnlabpy-0.0.3.0 → vislearnlabpy-0.0.3.2}/pyproject.toml +1 -1
  3. {vislearnlabpy-0.0.3.0 → vislearnlabpy-0.0.3.2}/src/vislearnlabpy/drawings/svg_render_helpers.py +11 -5
  4. {vislearnlabpy-0.0.3.0 → vislearnlabpy-0.0.3.2}/src/vislearnlabpy/extractions/drawingtask_extractor.py +35 -10
  5. {vislearnlabpy-0.0.3.0 → vislearnlabpy-0.0.3.2/src/vislearnlabpy.egg-info}/PKG-INFO +1 -1
  6. {vislearnlabpy-0.0.3.0 → vislearnlabpy-0.0.3.2}/LICENSE +0 -0
  7. {vislearnlabpy-0.0.3.0 → vislearnlabpy-0.0.3.2}/README.md +0 -0
  8. {vislearnlabpy-0.0.3.0 → vislearnlabpy-0.0.3.2}/setup.cfg +0 -0
  9. {vislearnlabpy-0.0.3.0 → vislearnlabpy-0.0.3.2}/src/vislearnlabpy/__init__.py +0 -0
  10. {vislearnlabpy-0.0.3.0 → vislearnlabpy-0.0.3.2}/src/vislearnlabpy/drawings/drawing.py +0 -0
  11. {vislearnlabpy-0.0.3.0 → vislearnlabpy-0.0.3.2}/src/vislearnlabpy/embeddings/embedding_store.py +0 -0
  12. {vislearnlabpy-0.0.3.0 → vislearnlabpy-0.0.3.2}/src/vislearnlabpy/embeddings/generate_embeddings.py +0 -0
  13. {vislearnlabpy-0.0.3.0 → vislearnlabpy-0.0.3.2}/src/vislearnlabpy/embeddings/similarity_generator.py +0 -0
  14. {vislearnlabpy-0.0.3.0 → vislearnlabpy-0.0.3.2}/src/vislearnlabpy/embeddings/similarity_utils.py +0 -0
  15. {vislearnlabpy-0.0.3.0 → vislearnlabpy-0.0.3.2}/src/vislearnlabpy/embeddings/stimuli_loader.py +0 -0
  16. {vislearnlabpy-0.0.3.0 → vislearnlabpy-0.0.3.2}/src/vislearnlabpy/embeddings/utils.py +0 -0
  17. {vislearnlabpy-0.0.3.0 → vislearnlabpy-0.0.3.2}/src/vislearnlabpy/extractions/mongo_extractor.py +0 -0
  18. {vislearnlabpy-0.0.3.0 → vislearnlabpy-0.0.3.2}/src/vislearnlabpy/models/clip_model.py +0 -0
  19. {vislearnlabpy-0.0.3.0 → vislearnlabpy-0.0.3.2}/src/vislearnlabpy/models/feature_generator.py +0 -0
  20. {vislearnlabpy-0.0.3.0 → vislearnlabpy-0.0.3.2}/src/vislearnlabpy/models/multimodal_model.py +0 -0
  21. {vislearnlabpy-0.0.3.0 → vislearnlabpy-0.0.3.2}/src/vislearnlabpy.egg-info/SOURCES.txt +0 -0
  22. {vislearnlabpy-0.0.3.0 → vislearnlabpy-0.0.3.2}/src/vislearnlabpy.egg-info/dependency_links.txt +0 -0
  23. {vislearnlabpy-0.0.3.0 → vislearnlabpy-0.0.3.2}/src/vislearnlabpy.egg-info/requires.txt +0 -0
  24. {vislearnlabpy-0.0.3.0 → vislearnlabpy-0.0.3.2}/src/vislearnlabpy.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: vislearnlabpy
3
- Version: 0.0.3.0
3
+ Version: 0.0.3.2
4
4
  Summary: Visual Learning Lab utility files and pipelines
5
5
  Author-email: Tarun Sepuri <tarunsepuri@gmail.com>
6
6
  License-Expression: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "vislearnlabpy"
7
- version = "0.0.3.0"
7
+ version = "0.0.3.2"
8
8
  authors = [
9
9
  { name="Tarun Sepuri", email="tarunsepuri@gmail.com" },
10
10
  ]
@@ -66,7 +66,8 @@ def render_and_save(Verts,
66
66
  Codes,
67
67
  stroke_settings: StrokeSettings = StrokeSettings(),
68
68
  save_dir=os.getcwd(),
69
- base_filename='strokes'):
69
+ base_filename='strokes',
70
+ last_stroke_only=False):
70
71
  '''
71
72
  input:
72
73
  line_width: how wide of strokes do we want? (int)
@@ -77,9 +78,10 @@ def render_and_save(Verts,
77
78
  rendered sketches into nested directories
78
79
 
79
80
  '''
80
- verts = Verts[0]
81
- codes = Codes[0]
82
81
  for i, verts in enumerate(Verts):
82
+ # if we're only rendering the last stroke
83
+ if last_stroke_only and i != len(Verts) - 1:
84
+ continue
83
85
  codes = Codes[i]
84
86
  fig = plt.figure(figsize=(stroke_settings.imsize, stroke_settings.imsize), frameon=False)
85
87
  ax = plt.subplot(111)
@@ -104,8 +106,12 @@ def render_and_save(Verts,
104
106
  ## save out as png
105
107
  ## maybe to make it not render every single thing, use plt.ioff
106
108
  os.makedirs(save_dir, exist_ok=True)
107
- # saving stroke count and not index so i+1
108
- fname = '{}_{}.png'.format(base_filename, i+1)
109
+ if not last_stroke_only:
110
+ # saving stroke count and not index so i+1
111
+ fname = f'{base_filename}_{i+1}.png'
112
+ else:
113
+ # not including stroke count in the name since we're only saving the final stroke
114
+ fname = f'{base_filename}.png'
109
115
  filepath = os.path.join(save_dir, fname)
110
116
  fig.savefig(filepath, bbox_inches='tight', pad_inches=0.0)
111
117
  plt.close(fig)
@@ -3,7 +3,7 @@ from io import StringIO
3
3
  import logging
4
4
 
5
5
  from typing import Optional, Tuple
6
- from vislearnlabpy.embeddings.stimuli_loader import ImageExtractor
6
+ from vislearnlabpy.embeddings.stimuli_loader import ImageExtractor, ImgExtractionSettings
7
7
  import io
8
8
  import base64
9
9
  from PIL import Image
@@ -76,7 +76,8 @@ class StrokeData:
76
76
  class DrawingsExtractor():
77
77
  @staticmethod
78
78
  def get_default_transformation():
79
- return ImageExtractor.get_transformations(apply_center_crop=False, apply_content_crop=True, use_thumbnail=True)
79
+ defualt_settings = ImgExtractionSettings()
80
+ return ImageExtractor.get_transformations(defualt_settings)
80
81
 
81
82
  @staticmethod
82
83
  def save_transformed(imgData, fname, transform=None):
@@ -97,6 +98,14 @@ class DrawingsExtractor():
97
98
  _im = np.array(im)
98
99
  return _im
99
100
 
101
+ @staticmethod
102
+ def save_transformed_file(fname, transform=None):
103
+ if transform is None:
104
+ transform = DrawingsExtractor.get_default_transformation()
105
+ img = Image.open(fname)
106
+ img = transform(img)
107
+ img.save(fname)
108
+
100
109
  @staticmethod
101
110
  def get_mean_intensity(img, imsize):
102
111
  thresh = 250
@@ -277,6 +286,7 @@ class DrawingTaskExtractor(MongoExtractor):
277
286
  return this_intensity, this_bounding_box
278
287
 
279
288
  def _output_filename(self, filename_prefix, run_name):
289
+ # todo: add more filename customization
280
290
  return os.path.join(self.output_dir, f"{filename_prefix}_final_{run_name}.csv")
281
291
 
282
292
  def _save_dataframe(self, data_dict, filename_prefix, run_name):
@@ -344,7 +354,7 @@ class DrawingTaskExtractor(MongoExtractor):
344
354
  age_part, participant_part = self._age_participant_parts(age, participant_id, session_id)
345
355
  return f"{category}_{extraction_type}_{age_part}{participant_part}{session_id}"
346
356
 
347
- def extract_images(self, image_dir=None, imsize=224, transform_file=False):
357
+ def extract_images(self, image_dir=None, imsize=224, transform_file=False, highres=False, stroke_settings=StrokeSettings(), transform_settings=None):
348
358
  if image_dir is None:
349
359
  image_dir = os.path.join(self.output_dir, 'sketches_full_dataset')
350
360
  # Initialize tracking variables
@@ -418,13 +428,28 @@ class DrawingTaskExtractor(MongoExtractor):
418
428
  draw_duration, intensity, bounding_box, imrec.get('age', None)
419
429
  )
420
430
  )
421
-
422
- # Save image files
423
- if transform_file:
424
- DrawingsExtractor.save_transformed(imrec['imgData'], fname)
431
+ if highres:
432
+ # Use the existing SVG helper functions
433
+ svg_list = make_svg_list(stroke_recs)
434
+ # Get verts and codes
435
+ Verts, Codes = get_verts_and_codes(svg_list)
436
+ # Render and save as PNGs
437
+ render_and_save(Verts,
438
+ Codes,
439
+ save_dir=category_dir,
440
+ base_filename=base_filename,
441
+ stroke_settings=stroke_settings,
442
+ last_stroke_only=True)
443
+ if transform_file:
444
+ DrawingsExtractor.save_transformed_file(fname, transform_settings)
445
+
425
446
  else:
426
- with open(fname, "wb") as fh:
427
- fh.write(base64.b64decode(imrec['imgData']))
447
+ # Save image files
448
+ if transform_file:
449
+ DrawingsExtractor.save_transformed(imrec['imgData'], fname, transform_settings)
450
+ else:
451
+ with open(fname, "wb") as fh:
452
+ fh.write(base64.b64decode(imrec['imgData']))
428
453
  write_count += 1
429
454
  if np.mod(write_count, 100) == 0:
430
455
  time_spent = (time.time() - time_start) / 60
@@ -491,7 +516,7 @@ class DrawingTaskExtractor(MongoExtractor):
491
516
  self._save_dataframe(trials, 'AllDescriptives_audio', self.collection.name)
492
517
  trials = []
493
518
  print(f"Finished processing {write_count} audio files")
494
-
519
+
495
520
  def extract_strokes(self, save_dir=None, save_type="png", stroke_settings=StrokeSettings(), **filters):
496
521
  """
497
522
  Extract stroke documents for all (or specified) sessions/trials.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: vislearnlabpy
3
- Version: 0.0.3.0
3
+ Version: 0.0.3.2
4
4
  Summary: Visual Learning Lab utility files and pipelines
5
5
  Author-email: Tarun Sepuri <tarunsepuri@gmail.com>
6
6
  License-Expression: MIT
File without changes