Skip to content

Commit a6aa619

Browse files
emilyfertigtensorflower-gardener
authored andcommitted
Add Pixel CNN++ distribution.
This is a Keras implementation of Pixel CNN++ by Salimans et al. (2017) (https://pdfs.semanticscholar.org/9e90/6792f67cbdda7b7777b69284a81044857656.pdf). PiperOrigin-RevId: 284616801
1 parent 4738452 commit a6aa619

File tree

7 files changed

+1532
-0
lines changed

7 files changed

+1532
-0
lines changed

LICENSE

+216
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,219 @@ Copyright 2018 The TensorFlow Probability Authors. All rights reserved.
201201
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
202202
See the License for the specific language governing permissions and
203203
limitations under the License.
204+
205+
------------------------------------------------------------------------
206+
207+
A file in TensorFlow Probability is also covered by the following license and
208+
copyright.
209+
210+
Files:
211+
- tensorflow_probability/python/distributions/pixel_cnn.py
212+
213+
Copyright 2019 OpenAI (http://openai.com)
214+
215+
Apache License
216+
Version 2.0, January 2004
217+
http://www.apache.org/licenses/
218+
219+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
220+
221+
1. Definitions.
222+
223+
"License" shall mean the terms and conditions for use, reproduction,
224+
and distribution as defined by Sections 1 through 9 of this document.
225+
226+
"Licensor" shall mean the copyright owner or entity authorized by
227+
the copyright owner that is granting the License.
228+
229+
"Legal Entity" shall mean the union of the acting entity and all
230+
other entities that control, are controlled by, or are under common
231+
control with that entity. For the purposes of this definition,
232+
"control" means (i) the power, direct or indirect, to cause the
233+
direction or management of such entity, whether by contract or
234+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
235+
outstanding shares, or (iii) beneficial ownership of such entity.
236+
237+
"You" (or "Your") shall mean an individual or Legal Entity
238+
exercising permissions granted by this License.
239+
240+
"Source" form shall mean the preferred form for making modifications,
241+
including but not limited to software source code, documentation
242+
source, and configuration files.
243+
244+
"Object" form shall mean any form resulting from mechanical
245+
transformation or translation of a Source form, including but
246+
not limited to compiled object code, generated documentation,
247+
and conversions to other media types.
248+
249+
"Work" shall mean the work of authorship, whether in Source or
250+
Object form, made available under the License, as indicated by a
251+
copyright notice that is included in or attached to the work
252+
(an example is provided in the Appendix below).
253+
254+
"Derivative Works" shall mean any work, whether in Source or Object
255+
form, that is based on (or derived from) the Work and for which the
256+
editorial revisions, annotations, elaborations, or other modifications
257+
represent, as a whole, an original work of authorship. For the purposes
258+
of this License, Derivative Works shall not include works that remain
259+
separable from, or merely link (or bind by name) to the interfaces of,
260+
the Work and Derivative Works thereof.
261+
262+
"Contribution" shall mean any work of authorship, including
263+
the original version of the Work and any modifications or additions
264+
to that Work or Derivative Works thereof, that is intentionally
265+
submitted to Licensor for inclusion in the Work by the copyright owner
266+
or by an individual or Legal Entity authorized to submit on behalf of
267+
the copyright owner. For the purposes of this definition, "submitted"
268+
means any form of electronic, verbal, or written communication sent
269+
to the Licensor or its representatives, including but not limited to
270+
communication on electronic mailing lists, source code control systems,
271+
and issue tracking systems that are managed by, or on behalf of, the
272+
Licensor for the purpose of discussing and improving the Work, but
273+
excluding communication that is conspicuously marked or otherwise
274+
designated in writing by the copyright owner as "Not a Contribution."
275+
276+
"Contributor" shall mean Licensor and any individual or Legal Entity
277+
on behalf of whom a Contribution has been received by Licensor and
278+
subsequently incorporated within the Work.
279+
280+
2. Grant of Copyright License. Subject to the terms and conditions of
281+
this License, each Contributor hereby grants to You a perpetual,
282+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
283+
copyright license to reproduce, prepare Derivative Works of,
284+
publicly display, publicly perform, sublicense, and distribute the
285+
Work and such Derivative Works in Source or Object form.
286+
287+
3. Grant of Patent License. Subject to the terms and conditions of
288+
this License, each Contributor hereby grants to You a perpetual,
289+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
290+
(except as stated in this section) patent license to make, have made,
291+
use, offer to sell, sell, import, and otherwise transfer the Work,
292+
where such license applies only to those patent claims licensable
293+
by such Contributor that are necessarily infringed by their
294+
Contribution(s) alone or by combination of their Contribution(s)
295+
with the Work to which such Contribution(s) was submitted. If You
296+
institute patent litigation against any entity (including a
297+
cross-claim or counterclaim in a lawsuit) alleging that the Work
298+
or a Contribution incorporated within the Work constitutes direct
299+
or contributory patent infringement, then any patent licenses
300+
granted to You under this License for that Work shall terminate
301+
as of the date such litigation is filed.
302+
303+
4. Redistribution. You may reproduce and distribute copies of the
304+
Work or Derivative Works thereof in any medium, with or without
305+
modifications, and in Source or Object form, provided that You
306+
meet the following conditions:
307+
308+
(a) You must give any other recipients of the Work or
309+
Derivative Works a copy of this License; and
310+
311+
(b) You must cause any modified files to carry prominent notices
312+
stating that You changed the files; and
313+
314+
(c) You must retain, in the Source form of any Derivative Works
315+
that You distribute, all copyright, patent, trademark, and
316+
attribution notices from the Source form of the Work,
317+
excluding those notices that do not pertain to any part of
318+
the Derivative Works; and
319+
320+
(d) If the Work includes a "NOTICE" text file as part of its
321+
distribution, then any Derivative Works that You distribute must
322+
include a readable copy of the attribution notices contained
323+
within such NOTICE file, excluding those notices that do not
324+
pertain to any part of the Derivative Works, in at least one
325+
of the following places: within a NOTICE text file distributed
326+
as part of the Derivative Works; within the Source form or
327+
documentation, if provided along with the Derivative Works; or,
328+
within a display generated by the Derivative Works, if and
329+
wherever such third-party notices normally appear. The contents
330+
of the NOTICE file are for informational purposes only and
331+
do not modify the License. You may add Your own attribution
332+
notices within Derivative Works that You distribute, alongside
333+
or as an addendum to the NOTICE text from the Work, provided
334+
that such additional attribution notices cannot be construed
335+
as modifying the License.
336+
337+
You may add Your own copyright statement to Your modifications and
338+
may provide additional or different license terms and conditions
339+
for use, reproduction, or distribution of Your modifications, or
340+
for any such Derivative Works as a whole, provided Your use,
341+
reproduction, and distribution of the Work otherwise complies with
342+
the conditions stated in this License.
343+
344+
5. Submission of Contributions. Unless You explicitly state otherwise,
345+
any Contribution intentionally submitted for inclusion in the Work
346+
by You to the Licensor shall be under the terms and conditions of
347+
this License, without any additional terms or conditions.
348+
Notwithstanding the above, nothing herein shall supersede or modify
349+
the terms of any separate license agreement you may have executed
350+
with Licensor regarding such Contributions.
351+
352+
6. Trademarks. This License does not grant permission to use the trade
353+
names, trademarks, service marks, or product names of the Licensor,
354+
except as required for reasonable and customary use in describing the
355+
origin of the Work and reproducing the content of the NOTICE file.
356+
357+
7. Disclaimer of Warranty. Unless required by applicable law or
358+
agreed to in writing, Licensor provides the Work (and each
359+
Contributor provides its Contributions) on an "AS IS" BASIS,
360+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
361+
implied, including, without limitation, any warranties or conditions
362+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
363+
PARTICULAR PURPOSE. You are solely responsible for determining the
364+
appropriateness of using or redistributing the Work and assume any
365+
risks associated with Your exercise of permissions under this License.
366+
367+
8. Limitation of Liability. In no event and under no legal theory,
368+
whether in tort (including negligence), contract, or otherwise,
369+
unless required by applicable law (such as deliberate and grossly
370+
negligent acts) or agreed to in writing, shall any Contributor be
371+
liable to You for damages, including any direct, indirect, special,
372+
incidental, or consequential damages of any character arising as a
373+
result of this License or out of the use or inability to use the
374+
Work (including but not limited to damages for loss of goodwill,
375+
work stoppage, computer failure or malfunction, or any and all
376+
other commercial damages or losses), even if such Contributor
377+
has been advised of the possibility of such damages.
378+
379+
9. Accepting Warranty or Additional Liability. While redistributing
380+
the Work or Derivative Works thereof, You may choose to offer,
381+
and charge a fee for, acceptance of support, warranty, indemnity,
382+
or other liability obligations and/or rights consistent with this
383+
License. However, in accepting such obligations, You may act only
384+
on Your own behalf and on Your sole responsibility, not on behalf
385+
of any other Contributor, and only if You agree to indemnify,
386+
defend, and hold each Contributor harmless for any liability
387+
incurred by, or claims asserted against, such Contributor by reason
388+
of your accepting any such warranty or additional liability.
389+
390+
END OF TERMS AND CONDITIONS
391+
392+
APPENDIX: How to apply the Apache License to your work.
393+
394+
To apply the Apache License to your work, attach the following
395+
boilerplate notice, with the fields enclosed by brackets "[]"
396+
replaced with your own identifying information. (Don't include
397+
the brackets!) The text should be enclosed in the appropriate
398+
comment syntax for the file format. We also recommend that a
399+
file or class name and description of purpose be included on the
400+
same "printed page" as the copyright notice for easier
401+
identification within third-party archives.
402+
403+
Copyright 2019 OpenAI (http://openai.com)
404+
405+
Licensed under the Apache License, Version 2.0 (the "License");
406+
you may not use this file except in compliance with the License.
407+
You may obtain a copy of the License at
408+
409+
http://www.apache.org/licenses/LICENSE-2.0
410+
411+
Unless required by applicable law or agreed to in writing, software
412+
distributed under the License is distributed on an "AS IS" BASIS,
413+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
414+
See the License for the specific language governing permissions and
415+
limitations under the License.
416+
417+
418+
419+

tensorflow_probability/python/distributions/BUILD

+35
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ py_library(
9393
":onehot_categorical",
9494
":pareto",
9595
":pert",
96+
":pixel_cnn",
9697
":plackett_luce",
9798
":poisson",
9899
":poisson_lognormal",
@@ -1043,6 +1044,27 @@ py_library(
10431044
],
10441045
)
10451046

1047+
py_library(
1048+
name = "pixel_cnn",
1049+
srcs = ["pixel_cnn.py"],
1050+
deps = [
1051+
":categorical",
1052+
":distribution",
1053+
":independent",
1054+
":logistic",
1055+
":mixture_same_family",
1056+
":quantized_distribution",
1057+
":transformed_distribution",
1058+
# numpy dep,
1059+
# tensorflow dep,
1060+
"//tensorflow_probability/python/bijectors:shift",
1061+
"//tensorflow_probability/python/internal:prefer_static",
1062+
"//tensorflow_probability/python/internal:reparameterization",
1063+
"//tensorflow_probability/python/internal:tensorshape_util",
1064+
"//tensorflow_probability/python/layers:weight_norm",
1065+
],
1066+
)
1067+
10461068
py_library(
10471069
name = "plackett_luce",
10481070
srcs = ["plackett_luce.py"],
@@ -2277,6 +2299,19 @@ py_test(
22772299
],
22782300
)
22792301

2302+
py_test(
2303+
name = "pixel_cnn_test",
2304+
size = "large",
2305+
srcs = ["pixel_cnn_test.py"],
2306+
shard_count = 8,
2307+
deps = [
2308+
# numpy dep,
2309+
# tensorflow dep,
2310+
"//tensorflow_probability",
2311+
"//tensorflow_probability/python/internal:test_util",
2312+
],
2313+
)
2314+
22802315
py_test(
22812316
name = "poisson_test",
22822317
size = "small",

tensorflow_probability/python/distributions/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
from tensorflow_probability.python.distributions.onehot_categorical import OneHotCategorical
8080
from tensorflow_probability.python.distributions.pareto import Pareto
8181
from tensorflow_probability.python.distributions.pert import PERT
82+
from tensorflow_probability.python.distributions.pixel_cnn import PixelCNN
8283
from tensorflow_probability.python.distributions.plackett_luce import PlackettLuce
8384
from tensorflow_probability.python.distributions.poisson import Poisson
8485
from tensorflow_probability.python.distributions.poisson_lognormal import PoissonLogNormalQuadratureCompound
@@ -184,6 +185,7 @@
184185
'LogitNormal',
185186
'NegativeBinomial',
186187
'Normal',
188+
'PixelCNN',
187189
'Poisson',
188190
'PoissonLogNormalQuadratureCompound',
189191
'ProbitBernoulli',

0 commit comments

Comments
 (0)