scope 0.3.0__tar.gz → 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.
scope-0.3.2/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2024 Danijar Hafner
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
@@ -1,9 +1,10 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: scope
3
- Version: 0.3.0
3
+ Version: 0.3.2
4
4
  Summary: Metrics logging and analysis
5
5
  Home-page: http://github.com/danijar/scope
6
6
  Classifier: Intended Audience :: Science/Research
7
7
  Classifier: License :: OSI Approved :: MIT License
8
8
  Classifier: Programming Language :: Python :: 3
9
9
  Description-Content-Type: text/markdown
10
+ License-File: LICENSE
@@ -1,2 +1,3 @@
1
1
  av
2
2
  numpy
3
+ pillow
@@ -1,4 +1,4 @@
1
- __version__ = '0.3.0'
1
+ __version__ = '0.3.2'
2
2
 
3
3
  from .reader import Reader
4
4
  from .writer import Writer
@@ -2,7 +2,6 @@ import io
2
2
  import struct
3
3
  import time
4
4
 
5
- import av
6
5
  import numpy as np
7
6
  import PIL.Image
8
7
 
@@ -127,12 +126,13 @@ class Video:
127
126
  return files_read(path)
128
127
 
129
128
  def encode(self, value):
129
+ import av
130
130
  if value.shape[-1] == 1:
131
131
  value = value.repeat(3, -1)
132
132
  T, H, W, _ = value.shape
133
133
  fp = io.BytesIO()
134
134
  output = av.open(fp, mode='w', format=self.ext)
135
- stream = output.add_stream(self.codec, rate=float(self.fps))
135
+ stream = output.add_stream(self.codec, rate=self.fps)
136
136
  stream.width = W
137
137
  stream.height = H
138
138
  stream.pix_fmt = 'yuv420p'
@@ -145,6 +145,7 @@ class Video:
145
145
  return fp.getvalue()
146
146
 
147
147
  def decode(self, buffer):
148
+ import av
148
149
  container = av.open(io.BytesIO(buffer))
149
150
  value = []
150
151
  for frame in container.decode(video=0):
@@ -14,7 +14,8 @@ FORMATS = [
14
14
 
15
15
  class Reader:
16
16
 
17
- def __init__(self, logdir, formats=FORMATS):
17
+ def __init__(self, logdir, formats=None):
18
+ formats = formats or FORMATS
18
19
  if isinstance(logdir, str):
19
20
  logdir = pathlib.Path(logdir)
20
21
  self.logdir = logdir
@@ -7,12 +7,13 @@ import numpy as np
7
7
 
8
8
  from . import formats
9
9
 
10
+ FPS = 10
10
11
 
11
12
  FORMATS = [
12
13
  formats.Text(),
13
14
  formats.Float(),
14
15
  formats.Image(),
15
- formats.Video(),
16
+ formats.Video(fps=FPS),
16
17
  ]
17
18
 
18
19
 
@@ -28,12 +29,12 @@ class Column:
28
29
 
29
30
  class Writer:
30
31
 
31
- def __init__(self, logdir, fps=20, workers=8, formats=FORMATS):
32
+ def __init__(self, logdir, workers=8, formats=None):
33
+ formats = formats or FORMATS
32
34
  if isinstance(logdir, str):
33
35
  logdir = pathlib.Path(logdir)
34
36
  self.logdir = logdir
35
37
  self.logdir.mkdir(parents=True, exist_ok=True)
36
- self.fps = fps
37
38
  self.workers = workers
38
39
  self.rng = np.random.default_rng(seed=None)
39
40
  self.fmts = FORMATS
@@ -1,9 +1,10 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: scope
3
- Version: 0.3.0
3
+ Version: 0.3.2
4
4
  Summary: Metrics logging and analysis
5
5
  Home-page: http://github.com/danijar/scope
6
6
  Classifier: Intended Audience :: Science/Research
7
7
  Classifier: License :: OSI Approved :: MIT License
8
8
  Classifier: Programming Language :: Python :: 3
9
9
  Description-Content-Type: text/markdown
10
+ License-File: LICENSE
@@ -1,3 +1,4 @@
1
+ LICENSE
1
2
  MANIFEST.in
2
3
  README.md
3
4
  pyproject.toml
@@ -1,2 +1,3 @@
1
1
  av
2
2
  numpy
3
+ pillow
@@ -14,13 +14,17 @@ class TestVideo:
14
14
  writer.add(0, {'foo': vid1})
15
15
  writer.add(5, {'foo': vid2})
16
16
  writer.flush()
17
- assert {x.name for x in logdir.glob('*')} == {'foo.mp4'}
18
- assert (logdir / 'foo.mp4' / 'index').stat().st_size == (8 + 8) * 2
19
- assert len(list((logdir / 'foo.mp4').glob('*'))) == 1 + 2
17
+ names = {x.name for x in logdir.glob('*')}
18
+ assert len(names) == 1
19
+ name = list(names)[0]
20
+ assert name in ('foo.mp4', 'foo.webm')
21
+ assert (logdir / name / 'index').stat().st_size == (8 + 8) * 2
22
+ assert len(list((logdir / name).glob('*'))) == 1 + 2
20
23
  reader = scope.Reader(logdir)
21
24
  assert reader.keys() == ('foo',)
22
25
  assert reader.length('foo') == 2
23
26
  steps, filenames = reader['foo']
24
- values = [reader.load('foo', x) for x in filenames]
25
27
  assert (steps == np.array([0, 5])).all()
26
- assert np.allclose(values, [vid1, vid2], rtol=0.1)
28
+ values = [reader.load('foo', x) for x in filenames]
29
+ assert all(x.dtype == np.uint8 for x in values)
30
+ assert np.allclose(values, [vid1, vid2], rtol=0.1, atol=3)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes