text stringlengths 0 93.6k |
|---|
r = {"video": self.cache["titles"][hl], "segments": self.cache["segments"][id] } |
return r |
# <FILESEP> |
# Copyright 2021 Google LLC |
# |
# Licensed under the Apache License, Version 2.0 (the "License"); |
# you may not use this file except in compliance with the License. |
# You may obtain a copy of the License at |
# |
# http://www.apache.org/licenses/LICENSE-2.0 |
# |
# Unless required by applicable law or agreed to in writing, software |
# distributed under the License is distributed on an "AS IS" BASIS, |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
# See the License for the specific language governing permissions and |
# limitations under the License. |
# Lint as: python3 |
"""Training script for Nerf.""" |
import functools |
import gc |
import time |
from absl import app |
from absl import flags |
import flax |
from flax.metrics import tensorboard |
from flax.training import checkpoints |
import jax |
from jax import random |
import jax.numpy as jnp |
import numpy as np |
from internal import datasets |
from internal import math |
from internal import models |
from internal import utils |
from internal import vis |
FLAGS = flags.FLAGS |
utils.define_common_flags() |
flags.DEFINE_integer('render_every', 5000, |
'The number of steps between test set image renderings.') |
jax.config.parse_flags_with_absl() |
def train_step(model, config, rng, state, batch, lr): |
"""One optimization step. |
Args: |
model: The linen model. |
config: The configuration. |
rng: jnp.ndarray, random number generator. |
state: utils.TrainState, state of the model/optimizer. |
batch: dict, a mini-batch of data for training. |
lr: float, real-time learning rate. |
Returns: |
new_state: utils.TrainState, new training state. |
stats: list. [(loss, psnr), (loss_coarse, psnr_coarse)]. |
rng: jnp.ndarray, updated random number generator. |
""" |
rng, key = random.split(rng) |
def loss_fn(variables): |
def tree_sum_fn(fn): |
return jax.tree_util.tree_reduce( |
lambda x, y: x + fn(y), variables, initializer=0) |
weight_l2 = config.weight_decay_mult * ( |
tree_sum_fn(lambda z: jnp.sum(z**2)) / |
tree_sum_fn(lambda z: jnp.prod(jnp.array(z.shape)))) |
ret = model.apply( |
variables, |
key, |
batch['rays'], |
randomized=config.randomized, |
white_bkgd=config.white_bkgd) |
mask = batch['rays'].lossmult |
if config.disable_multiscale_loss: |
mask = jnp.ones_like(mask) |
losses = [] |
for (rgb, _, _) in ret: |
losses.append( |
(mask * (rgb - batch['pixels'][..., :3])**2).sum() / mask.sum()) |
losses = jnp.array(losses) |
loss = ( |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.