1 Star 0 Fork 0

gmachine1729 / MineSweeperNeuralNet

Create your Gitee Account
Explore and code with more than 6 million developers,Free private repositories !:)
Sign up
This repository doesn't specify license. Without author's permission, this code is only for learning and cannot be used for other purposes.
Clone or download
trainModelBackground.py 1.56 KB
Copy Edit Web IDE Raw Blame History
from MineSweeperLearner import MineSweeperLearner
import imp
import sys, getopt
from keras.models import load_model
#called like this:
#python trainModelBackground.py -o [option] -m [model] -b [batches] -g [gamesPerBatch]
def main(argv):
option = ''
modelChoice = ''
nBatches = 1000
nSamples = 1000
epochsPerBatch = 1
try:
opts, args = getopt.getopt(argv, "ho:m:b:s:e:", ["option=", "model=", "batches=", "nSamples=", "epochsPerBatch="])
except getopt.GetoptError:
print('trainModelBackground.py -o <option> -m <model>')
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print('trainModelBackground.py -o <option> -m <model>')
sys.exit()
elif opt in ("-o", "--option"):
option = arg
elif opt in ("-m", "--model"):
modelChoice = arg
elif opt in ("-b", "--batches"):
nBatches = int(arg)
elif opt in ("-s", "--nSamples"):
nSamples = int(arg)
elif opt in ("-e", "--epochsPerBatch"):
epochsPerBatch = int(arg)
if option == "trainNew":
modelSource = imp.load_source(modelChoice, "modelCode/" + modelChoice + ".py")
model = modelSource.model
elif option == "continueTraining":
model = load_model("trainedModels/" + modelChoice + ".h5")
learner = MineSweeperLearner(modelChoice, model)
learner.learnMineSweeper(nSamples, nBatches, epochsPerBatch, verbose=True)
learner.model.save("trainedModels/" + modelChoice + ".h5")
if __name__ == "__main__":
main(sys.argv[1:])

Comment ( 0 )

Sign in for post a comment

Python
1
https://gitee.com/gmachine1729/MineSweeperNeuralNet.git
git@gitee.com:gmachine1729/MineSweeperNeuralNet.git
gmachine1729
MineSweeperNeuralNet
MineSweeperNeuralNet
master

Search