Beispiel #1
0
def calc_loss_and_print(y_data, print_dir, step, N):
    val_loss, orig_loss, n_batch = 0, 0, 0
    for b in range(int(y_data.shape[0] / FLAGS.batch_size)):
        y_batch = y_data[b * FLAGS.batch_size:(b + 1) *
                         FLAGS.batch_size, :, :, :]
        feed_dict = {y_: y_batch}

        if FLAGS.regularization > 0:
            err1, err2, xeval, ypred, xtpred, ytpred = sess.run(
                [cost, cost_input_output, y_l, y, y_s, y_t],
                feed_dict=feed_dict)
        else:
            err1, err2, xeval, ypred = sess.run(
                [cost, cost_input_output, y_l, y], feed_dict=feed_dict)

        val_loss += err1
        orig_loss += err2
        n_batch += 1
        batch_dir = print_dir

        if y_data.shape[0] > y_batch.shape[0]:
            batch_dir = '%s/batch_%03d' % (print_dir, n_batch)

        if n_batch <= N or N < 0:
            if not os.path.exists(batch_dir):
                os.makedirs(batch_dir)
            for i in range(0, y_batch.shape[0]):
                # Print LDR samples
                if FLAGS.print_im:
                    img_io.writeLDR(
                        np.squeeze(xeval[i]),
                        "%s/%06d_%03d_in.png" % (batch_dir, step, i + 1))
                    img_io.writeLDR(
                        np.squeeze(y_batch[i]),
                        "%s/%06d_%03d_gt.png" % (batch_dir, step, i + 1))
                    img_io.writeLDR(
                        np.squeeze(ypred[i]),
                        "%s/%06d_%03d_out.png" % (batch_dir, step, i + 1))

                    if FLAGS.regularization > 0:
                        img_io.writeLDR(
                            np.squeeze(xtpred[i]), "%s/%06d_%03d_out_R.png" %
                            (batch_dir, step, i + 1))
                        img_io.writeLDR(
                            np.squeeze(ytpred[i]), "%s/%06d_%03d_out_T.png" %
                            (batch_dir, step, i + 1))

    return (val_loss / n_batch, orig_loss / n_batch)
Beispiel #2
0
        y_predict = sess.run([y], feed_dict=feed_dict)
        y_predict = np.power(np.maximum(y_predict, 0.0), FLAGS.gamma)
        print_("\tdone\n")

        # Gamma corrected output 用伽马校正代替色调映射
        y_gamma = np.power(np.maximum(y_predict, 0.0), 0.5)

        # Write to disc
        print_("\tWriting...")
        k += 1

        # 仅仅对过曝光区域进行了细节增强
        image_name = frames[i]
        image_name_out = image_name[image_name.find("/")+1:image_name.find(".")]
        print("image_name_out:%s" % image_name_out)
        img_io.writeLDR(x_buffer, '%s/%s_in_%d.png' % (FLAGS.out_dir,image_name_out, k), -3)  # -3的曝光度
        img_io.writeLDR(y_gamma, '%s/%s_out_%d.png' % (FLAGS.out_dir,image_name_out, k), -3)
        # 对曝光度增强没有效果-》欠曝光细节没有增强

        img_io.writeEXR(y_predict, '%s/%s_out_%d.exr' % (FLAGS.out_dir,image_name_out, k))
        print_("\tdone\n")

    except img_io.IOException as e:
        print_("\n\t\tWarning! ", 'w', True)
        print_("%s\n" % e, 'w')
    except Exception as e:
        print_("\n\t\tError: ", 'e', True)
        print_("%s\n" % e, 'e')

print_("Done!\n")
                    # g alters this according to y = f(x^(1/g))^g
                    print_("\tInference...")
                    feed_dict = {y_: np.power(np.maximum(y_buffer, 0.0), 1.0/FLAGS.gamma)}
                    if FLAGS.input:
                        x_buffer = sess.run(x, feed_dict=feed_dict)
                    else:
                        x_buffer, y_predict = sess.run([x,y], feed_dict=feed_dict)
                    print_("\tdone\n")

                    # Write to disc
                    print_("\tWriting...")
                    for b in range(FLAGS.batch_size):
                        k += 1;
                        #img_io.writeLDR(np.squeeze(y_buffer[b,:,:,:]), '%s/%06d_gt.png' % (out_dir, k), -3)
                        if FLAGS.input:
                            img_io.writeLDR(np.squeeze(x_buffer[b,:,:]), '%s/%06d.png' % (out_dir, k), -3)
                        else:
                            img_io.writeLDR(np.squeeze(y_predict[b,:,:,:]), '%s/%06d.png' % (out_dir, k), -3)
                    print_("\tdone\n")

            except img_io.IOException as e:
                print_("\n\t\tWarning! ", 'w', True)
                print_("%s\n"%e, 'w')
            except Exception as e:    
                print_("\n\t\tError: ", 'e', True)
                print_("%s\n"%e, 'e')

        print_("Done!\n")


Beispiel #4
0
def calc_loss_and_print(x_data, y_data, print_dir, step, N):
    val_loss, orig_loss, n_batch = 0, 0, 0
    for b in range(int(x_data.shape[0] / FLAGS.batch_size)):
        x_batch = x_data[b * FLAGS.batch_size:(b + 1) *
                         FLAGS.batch_size, :, :, :]
        y_batch = y_data[b * FLAGS.batch_size:(b + 1) *
                         FLAGS.batch_size, :, :, :]
        feed_dict = {x: x_batch, y_: y_batch}
        err1, err2, y_predict, y_gt, M = sess.run(
            [cost, cost_input_output, y, y_, msk], feed_dict=feed_dict)

        val_loss += err1
        orig_loss += err2
        n_batch += 1
        batch_dir = print_dir

        if x_data.shape[0] > x_batch.shape[0]:
            batch_dir = '%s/batch_%03d' % (print_dir, n_batch)

        if n_batch <= N or N < 0:
            if not os.path.exists(batch_dir):
                os.makedirs(batch_dir)
            for i in range(0, x_batch.shape[0]):
                yy_p = np.squeeze(y_predict[i])
                xx = np.squeeze(x_batch[i])
                yy = np.squeeze(y_gt[i])
                mm = np.squeeze(M[i])

                # Apply inverse camera curve
                x_lin = np.power(
                    np.divide(0.6 * xx, np.maximum(1.6 - xx, 1e-10)),
                    1.0 / 0.9)

                # Transform log predictions to linear domain
                yy_p = np.exp(yy_p) - eps

                # Masking
                y_final = (1 - mm) * x_lin + mm * yy_p

                # Gamma correction
                yy_p = np.power(np.maximum(yy_p, 0.0), 0.5)
                y_final = np.power(np.maximum(y_final, 0.0), 0.5)
                yy = np.power(np.maximum(yy, 0.0), 0.5)
                xx = np.power(np.maximum(x_lin, 0.0), 0.5)

                # Print LDR samples
                if FLAGS.print_im:
                    img_io.writeLDR(
                        xx, "%s/%06d_%03d_in.png" % (batch_dir, step, i + 1),
                        -3)
                    img_io.writeLDR(
                        yy, "%s/%06d_%03d_gt.png" % (batch_dir, step, i + 1),
                        -3)
                    img_io.writeLDR(
                        y_final,
                        "%s/%06d_%03d_out.png" % (batch_dir, step, i + 1), -3)

                # Print HDR samples
                if FLAGS.print_hdr:
                    img_io.writeEXR(
                        xx, "%s/%06d_%03d_in.exr" % (batch_dir, step, i + 1))
                    img_io.writeEXR(
                        yy, "%s/%06d_%03d_gt.exr" % (batch_dir, step, i + 1))
                    img_io.writeEXR(
                        y_final,
                        "%s/%06d_%03d_out.exr" % (batch_dir, step, i + 1))

    return (val_loss / n_batch, orig_loss / n_batch)
        # the reconstructed highlights. If y = f(x) is the reconstruction, the gamma
        # g alters this according to y = f(x^(1/g))^g
        print_("\tInference...")
        feed_dict = {x: np.power(np.maximum(x_buffer, 0.0), 1.0 / FLAGS.gamma)}
        y_predict = sess.run([y], feed_dict=feed_dict)
        y_predict = np.power(np.maximum(y_predict, 0.0), FLAGS.gamma)
        print_("\tdone\n")

        # Gamma corrected output
        y_gamma = np.power(np.maximum(y_predict, 0.0), 0.5)

        # Write to disc
        print_("\tWriting...")
        k += 1
        # img_io.writeLDR(x_buffer, '%s/%06d_in.jpg' % (FLAGS.out_dir, k), -3)
        # img_io.writeLDR(y_gamma, '%s/%06d_out.jpg' % (FLAGS.out_dir, k), -3)
        # img_io.writeEXR(y_predict, '%s/%06d_out.exr' % (FLAGS.out_dir, k))
        img_io.writeLDR(y_predict, '%s/%06d_predict.jpg' % (FLAGS.out_dir, k))
        print_("\tdone\n")

    except img_io.IOException as e:
        print_("\n\t\tWarning! ", 'w', True)
        print_("%s\n" % e, 'w')
    except Exception as e:
        print_("\n\t\tError: ", 'e', True)
        print_("%s\n" % e, 'e')

print_("Done!\n")

sess.close()
        print_("\t(Saturation: %0.2f%%)\n" % (100.0*(x_buffer>=1).sum()/x_buffer.size), 'm')

        # Run prediction
        print_("\tInference...")
        feed_dict = {x: x_buffer}
        y_predict = sess.run([y], feed_dict=feed_dict)
        print_("\tdone\n")

        # Gamma corrected output
        y_gamma = np.power(np.maximum(y_predict, 0.0), 0.5)

        # Write to disc
        print_("\tWriting...")
        k += 1;
        img_io.writeLDR(x_buffer, '%s/%06d_in.png' % (FLAGS.out_dir, k), -3)
        img_io.writeLDR(y_gamma, '%s/%06d_out.png' % (FLAGS.out_dir, k), -3)
        img_io.writeEXR(y_predict, '%s/%06d_out.exr' % (FLAGS.out_dir, k))
        print_("\tdone\n")

    except img_io.IOException as e:
        print_("\n\t\tWarning! ", 'w', True)
        print_("%s\n"%e, 'w')
    except Exception as e:    
        print_("\n\t\tError: ", 'e', True)
        print_("%s\n"%e, 'e')

print_("Done!\n")

sess.close()