outputs = netG(inputs) outputs_cpu = outputs.data.cpu().numpy() lossL1 = criterionL1(outputs, targets) L1val_accum += lossL1.item() if i == 0: input_ndarray = inputs_cpu.cpu().numpy()[0] v_norm = (np.max(np.abs(input_ndarray[0, :, :]))**2 + np.max(np.abs(input_ndarray[1, :, :]))**2)**0.5 outputs_denormalized = data.denormalize(outputs_cpu[0], v_norm) targets_denormalized = data.denormalize( targets_cpu.cpu().numpy()[0], v_norm) utils.makeDirs(["results_train"]) utils.imageOut("results_train/epoch{}_{}".format(epoch, i), outputs_denormalized, targets_denormalized, saveTargets=True) # data for graph plotting L1_accum /= len(trainLoader) L1val_accum /= len(valiLoader) if saveL1: if epoch == 0: utils.resetLog(prefix + "L1.txt") utils.resetLog(prefix + "L1val.txt") utils.log(prefix + "L1.txt", "{} ".format(L1_accum), False) utils.log(prefix + "L1val.txt", "{} ".format(L1val_accum), False)
#fileName = dataDir + str(uuid.uuid4()) # randomized name fileName = dataDir + "%s_%d_%d" % (basename, int( freestreamX * 100), int(freestreamY * 100)) print("\tsaving in " + fileName + ".npz") np.savez_compressed(fileName, a=npOutput) files = os.listdir(airfoil_database) files.sort() if len(files) == 0: print("error - no airfoils found in %s" % airfoil_database) exit(1) utils.makeDirs([ "./data_pictures", "./train", "./OpenFOAM/constant/polyMesh/sets", "./OpenFOAM/constant/polyMesh" ]) # main fout = open('train.txt', 'wt') for n in range(samples): print("Run {}:".format(n)) print("Run {}:".format(n), file=fout) #fileNumber = np.random.randint(0, len(files)) #basename = os.path.splitext( os.path.basename(files[fileNumber]) )[0] #print("\tusing {}".format(files[fileNumber])) #print("\tusing {}".format(files[fileNumber]), file=fout) basename = 'cylinder.dat'
targets = Variable(targets) targets = targets.cuda() inputs = torch.FloatTensor(1, 3, res, res) inputs = Variable(inputs) inputs = inputs.cuda() targets_dn = torch.FloatTensor(1, 3, res, res) targets_dn = Variable(targets_dn) targets_dn = targets_dn.cuda() outputs_dn = torch.FloatTensor(1, 3, res, res) outputs_dn = Variable(outputs_dn) outputs_dn = outputs_dn.cuda() netG = TurbNetG(channelExponent=expo) lf = "./" + prefix + "testout{}.txt".format(suffix) utils.makeDirs(["results_test"]) # loop over different trained models avgLoss = 0. losses = [] models = [] loss_p_list = [] loss_v_list = [] accum_list = [] for si in range(25): s = chr(96 + si) if (si == 0): s = "" # check modelG, and modelG + char modelFn = "./" + prefix + "modelG{}{}".format(suffix, s) if not os.path.isfile(modelFn):
def init(): '''init repository''' try: utils.makeDirs(getPath()) except Exception as e: raise Exception('could not init repository. reason: {reason}'.format(reason = e.message))