kyamagu commited on
Commit
e191d83
1 Parent(s): 1cef023

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +53 -0
README.md CHANGED
@@ -795,6 +795,15 @@ Each instance has scalar attributes (canvas) and sequence attributes (elements).
795
  <PIL.PngImagePlugin.PngImageFile image mode=RGBA size=256x256>]}
796
  ```
797
 
 
 
 
 
 
 
 
 
 
798
  ### Data Fields
799
 
800
  In the following, categorical fields are shown as `categorical` type, but the actual storage is `int64`.
@@ -851,6 +860,50 @@ The Crello dataset has 3 splits: train, validation, and test. The current split
851
  | test | 2371 |
852
 
853
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
854
  ## Dataset Creation
855
 
856
  ### Curation Rationale
 
795
  <PIL.PngImagePlugin.PngImageFile image mode=RGBA size=256x256>]}
796
  ```
797
 
798
+ To get a label for categorical values, use the `int2str` method:
799
+
800
+ ```python
801
+ key = "font"
802
+ example = dataset[0]
803
+
804
+ dataset.features[key].int2str(example[key])
805
+ ```
806
+
807
  ### Data Fields
808
 
809
  In the following, categorical fields are shown as `categorical` type, but the actual storage is `int64`.
 
860
  | test | 2371 |
861
 
862
 
863
+ ### Visualization
864
+
865
+ Each example can be visualized in the following approach. Note the following does not guarantee a similar appearance to the original template.
866
+
867
+ ```python
868
+ def render(dataset: datasets.Dataset, example: Dict[str, Any], max_size: float=512.) -> bytes:
869
+ """Render parsed sequence example onto an image and return as PNG bytes."""
870
+ canvas_width = int(dataset.features["canvas_width"].int2str(example["canvas_width"]))
871
+ canvas_height = int(dataset.features["canvas_height"].int2str(example["canvas_height"]))
872
+
873
+ scale = min(1.0, max_size / canvas_width, max_size / canvas_height)
874
+
875
+ surface = skia.Surface(int(scale * canvas_width), int(scale * canvas_height))
876
+ with surface as canvas:
877
+ canvas.scale(scale, scale)
878
+ for index in range(example["length"]):
879
+ pil_image = example["image"][index]
880
+ image = skia.Image.frombytes(
881
+ pil_image.convert('RGBA').tobytes(),
882
+ pil_image.size,
883
+ skia.kRGBA_8888_ColorType)
884
+ left = example["left"][index] * canvas_width
885
+ top = example["top"][index] * canvas_height
886
+ width = example["width"][index] * canvas_width
887
+ height = example["height"][index] * canvas_height
888
+ rect = skia.Rect.MakeXYWH(left, top, width, height)
889
+
890
+ angle = example["angle"][index]
891
+ if angle != 0:
892
+ degree = 180. * angle / np.pi
893
+ canvas.save()
894
+ canvas.rotate(degree, left + width / 2., top + height / 2.)
895
+
896
+ canvas.drawImageRect(image, rect)
897
+ if angle != 0:
898
+ canvas.restore()
899
+
900
+ image = surface.makeImageSnapshot()
901
+ with io.BytesIO() as f:
902
+ image.save(f, skia.kPNG)
903
+ return f.getvalue()
904
+ ```
905
+
906
+
907
  ## Dataset Creation
908
 
909
  ### Curation Rationale