Beispiel #1
0
from torch.autograd import Variable, grad

import GAN
import utils
import visdom

import numpy as np
import sys
import os
import pickle

torch.manual_seed(1)

#============ PARSE ARGUMENTS =============

args = utils.setup_args()
args.save_name = args.save_file + args.env
print(args)

#============ GRADIENT PENALTY (for discriminator) ================


def calc_gradient_penalty(netD, real_data, fake_data):
    alpha = torch.rand(real_data.size(0), 1)
    alpha = alpha.expand(real_data.size())

    if torch.cuda.is_available():
        alpha = alpha.cuda()

    interpolates = alpha * real_data + ((1 - alpha) * fake_data)
Beispiel #2
0
        }

        if test_summary['test_acc'] > best_accuracy:
            best_accuracy = test_summary['test_acc']
            current_state['best_acc'] = best_accuracy
            save_checkpoint(current_state=current_state,
                            filename=os.path.join(args.save_dir,
                                                  "models/best.pth"))

        logger.info("Best accuracy: %s" % best_accuracy)

        if epoch % args.save_freq == 0:
            save_checkpoint(current_state=current_state,
                            filename=os.path.join(
                                args.save_dir, "models/epoch_%s.pth" % epoch))

        save_checkpoint(current_state=current_state,
                        filename=os.path.join(args.save_dir,
                                              "models/last.pth"))

        if args.use_gpu:
            net.cuda()


if __name__ == "__main__":
    args = setup_args()
    os.makedirs(os.path.join(args.save_dir, "models"), exist_ok=True)
    logger = setup_logger(name="training_log", save_dir=args.save_dir)
    logger.info(args)
    run_training(args, logger)
Beispiel #3
0
	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.
"""

import utils
import json

assets = utils.setup_args('Utility script to extract namespaces from MC: PE/W10/EDU JSON files.')

namespaces = list()

print('\nAnalyzing \'_ui_defs.json\'...\n')
ui_defs = json.loads(utils.get_clean_json(assets + '/ui/_ui_defs.json'))

for ui_file in ui_defs['ui_defs']:
	print('Analyzing \'{}\'...'.format(ui_file))
	ui_json = json.loads(utils.get_clean_json(assets + '/' + ui_file))
	namespaces.append(ui_json['namespace'])

print('\nRemoving duplicates...')
for ns in namespaces:
	i = namespaces.count(ns)
	while i > 1: