Skip to content

Commit

Permalink
reorganize and delete a lot of bloat
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexicon226 committed Mar 22, 2024
1 parent 3ba9efc commit 28d7ec1
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 318 deletions.
9 changes: 8 additions & 1 deletion CompositeEnvironment.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from Terrain import generator
import matplotlib.pyplot as plt
from DNoise.dnoise import EncoderDecoder as ed
from Terrain.timer import FunctionTimer
import torch
from torch import nn

Expand Down Expand Up @@ -81,7 +82,14 @@ def dNoiseVis(self, inputpic):
inputpic = torch.tensor(inputpic, dtype=torch.float32).view(1, 1, 256, 256)
inputpic = inputpic.type(torch.cuda.FloatTensor)

de_noise_timer = FunctionTimer("De-Noising")
de_noise_timer.start()

de_noised_image = model(inputpic)

de_noise_timer.stop()
de_noise_timer.print()

loss = loss_fn(de_noised_image, inputpic)

loss = (1 - loss.item()) * 100
Expand Down Expand Up @@ -154,5 +162,4 @@ def thresholdDNoise(input, x):
masked = ev.generate()

vi = Visualizer("./DNoise/models/synthnav-model-0.pth", pic)

vi.dNoiseVis(masked)
14 changes: 7 additions & 7 deletions DNoise/array2img.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,30 @@
import threading
from Terrain import generator
import math
from Terrain import timers
from Terrain import timer
import os


def array2image(x, y, octaves, weight, seed: int = 0, iD: int = 0):
timer = timers.FunctionTimer("Clean - Generate")
timer = timer.FunctionTimer("Clean - Generate")
array = generator.generateClean(x, y, octaves, seed)
timer.stop()
bool_array = np.array(array, dtype=bool)
timer = timers.FunctionTimer("Clean - To Image")
timer = timer.FunctionTimer("Clean - To Image")
img = PIL.Image.fromarray(bool_array)
print(img)
timer.stop()
timer = timers.FunctionTimer("Clean - Image Save")
timer = timer.FunctionTimer("Clean - Image Save")
img.save("./val_images/clean/" + str(iD) + "_clean.jpeg", bits=1, optimize=True)
timer.stop()
timer = timers.FunctionTimer("Noisy - Generate")
timer = timer.FunctionTimer("Noisy - Generate")
array = generator.generateNoise(x, y, octaves, weight, seed)
timer.stop()
bool_array = np.array(array, dtype=bool)
timer = timers.FunctionTimer("Noisy - To Image")
timer = timer.FunctionTimer("Noisy - To Image")
img = PIL.Image.fromarray(bool_array)
timer.stop()
timer = timers.FunctionTimer("Noisy - Image Save")
timer = timer.FunctionTimer("Noisy - Image Save")
img.save("./val_images/noisy/" + str(iD) + "_noisy.jpeg", bits=1, optimize=True)
timer.stop()

Expand Down
286 changes: 0 additions & 286 deletions DNoise/helper_functions.py

This file was deleted.

2 changes: 1 addition & 1 deletion Pathfinding/astar.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import random

from Terrain.timers import FunctionTimer
from Terrain.timer import FunctionTimer
from CompositeEnvironment import Visualizer, Environment
from Terrain import pathcheck, generator

Expand Down
2 changes: 1 addition & 1 deletion Terrain/border.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import copy

import Terrain.terraingen as terraingen
from Terrain.timers import FunctionTimer
from Terrain.timer import FunctionTimer
from typing import Union
import numpy as np

Expand Down
13 changes: 13 additions & 0 deletions Terrain/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""
A series of helper functions used throughout the course.
If a function gets defined once and could be used over and over, it'll go in here.
"""

from math import floor, log10

def round_sig(x, sig=2):
"""
Rounds `x` to `sig` significant figures.
"""
return round(x, sig - int(floor(log10(abs(x)))) - 1)
2 changes: 1 addition & 1 deletion Terrain/pathcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import sys

import Terrain.terraingen as terraingen
from Terrain.timers import FunctionTimer
from Terrain.timer import FunctionTimer


def path(x: int, y: int, octaves: int, progress: bool = False, setseed: int = 0):
Expand Down
Loading

0 comments on commit 28d7ec1

Please sign in to comment.