How to run several times a model in tensorflow?
I want to train several times a file ConvNet.py in order to produce some statistics about its training like precision, confussion matrices, etc. So, I tried (in google colab) to do something like
for k in range(10:
%run ConvNet.py
The first training goes well, but when in begin the second, arise a problem. It says that "weights variable already defined, disallowed" (weights is the fist variable that I define in ConvNet.py) and the script stops.
I tried clearing variables with os kill, but there is still problems. How can I fix this?
python tensorflow google-colaboratory
add a comment |
I want to train several times a file ConvNet.py in order to produce some statistics about its training like precision, confussion matrices, etc. So, I tried (in google colab) to do something like
for k in range(10:
%run ConvNet.py
The first training goes well, but when in begin the second, arise a problem. It says that "weights variable already defined, disallowed" (weights is the fist variable that I define in ConvNet.py) and the script stops.
I tried clearing variables with os kill, but there is still problems. How can I fix this?
python tensorflow google-colaboratory
add a comment |
I want to train several times a file ConvNet.py in order to produce some statistics about its training like precision, confussion matrices, etc. So, I tried (in google colab) to do something like
for k in range(10:
%run ConvNet.py
The first training goes well, but when in begin the second, arise a problem. It says that "weights variable already defined, disallowed" (weights is the fist variable that I define in ConvNet.py) and the script stops.
I tried clearing variables with os kill, but there is still problems. How can I fix this?
python tensorflow google-colaboratory
I want to train several times a file ConvNet.py in order to produce some statistics about its training like precision, confussion matrices, etc. So, I tried (in google colab) to do something like
for k in range(10:
%run ConvNet.py
The first training goes well, but when in begin the second, arise a problem. It says that "weights variable already defined, disallowed" (weights is the fist variable that I define in ConvNet.py) and the script stops.
I tried clearing variables with os kill, but there is still problems. How can I fix this?
python tensorflow google-colaboratory
python tensorflow google-colaboratory
asked Dec 30 '18 at 23:26
Veridian DynamicsVeridian Dynamics
1336
1336
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
It's probably better if you do the iterated training in Python directly.
You haven't shared much about your setup, but you can do something like:
import tensorflow as tf
mnist = tf.keras.datasets.mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
def build_model():
model = tf.keras.models.Sequential()
model.add(tf.keras.layers.Flatten(input_shape=(28,28,)))
model.add(tf.keras.layers.Dense(32, activation="relu"))
model.add(tf.keras.layers.Dense(10, activation="sigmoid"))
model.compile(optimizer=tf.train.AdamOptimizer(),
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
return model
for i in range(10):
model = build_model()
model.fit(x_train, y_train)
model.save_weights(f"./weights-{i}.hdf5")
And when you want to do the analysis:
for i in range(10):
model = build_model()
model.load_weights(f"./weights-{i}.hdf5")
do_analysis(model)
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53982255%2fhow-to-run-several-times-a-model-in-tensorflow%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
It's probably better if you do the iterated training in Python directly.
You haven't shared much about your setup, but you can do something like:
import tensorflow as tf
mnist = tf.keras.datasets.mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
def build_model():
model = tf.keras.models.Sequential()
model.add(tf.keras.layers.Flatten(input_shape=(28,28,)))
model.add(tf.keras.layers.Dense(32, activation="relu"))
model.add(tf.keras.layers.Dense(10, activation="sigmoid"))
model.compile(optimizer=tf.train.AdamOptimizer(),
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
return model
for i in range(10):
model = build_model()
model.fit(x_train, y_train)
model.save_weights(f"./weights-{i}.hdf5")
And when you want to do the analysis:
for i in range(10):
model = build_model()
model.load_weights(f"./weights-{i}.hdf5")
do_analysis(model)
add a comment |
It's probably better if you do the iterated training in Python directly.
You haven't shared much about your setup, but you can do something like:
import tensorflow as tf
mnist = tf.keras.datasets.mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
def build_model():
model = tf.keras.models.Sequential()
model.add(tf.keras.layers.Flatten(input_shape=(28,28,)))
model.add(tf.keras.layers.Dense(32, activation="relu"))
model.add(tf.keras.layers.Dense(10, activation="sigmoid"))
model.compile(optimizer=tf.train.AdamOptimizer(),
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
return model
for i in range(10):
model = build_model()
model.fit(x_train, y_train)
model.save_weights(f"./weights-{i}.hdf5")
And when you want to do the analysis:
for i in range(10):
model = build_model()
model.load_weights(f"./weights-{i}.hdf5")
do_analysis(model)
add a comment |
It's probably better if you do the iterated training in Python directly.
You haven't shared much about your setup, but you can do something like:
import tensorflow as tf
mnist = tf.keras.datasets.mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
def build_model():
model = tf.keras.models.Sequential()
model.add(tf.keras.layers.Flatten(input_shape=(28,28,)))
model.add(tf.keras.layers.Dense(32, activation="relu"))
model.add(tf.keras.layers.Dense(10, activation="sigmoid"))
model.compile(optimizer=tf.train.AdamOptimizer(),
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
return model
for i in range(10):
model = build_model()
model.fit(x_train, y_train)
model.save_weights(f"./weights-{i}.hdf5")
And when you want to do the analysis:
for i in range(10):
model = build_model()
model.load_weights(f"./weights-{i}.hdf5")
do_analysis(model)
It's probably better if you do the iterated training in Python directly.
You haven't shared much about your setup, but you can do something like:
import tensorflow as tf
mnist = tf.keras.datasets.mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
def build_model():
model = tf.keras.models.Sequential()
model.add(tf.keras.layers.Flatten(input_shape=(28,28,)))
model.add(tf.keras.layers.Dense(32, activation="relu"))
model.add(tf.keras.layers.Dense(10, activation="sigmoid"))
model.compile(optimizer=tf.train.AdamOptimizer(),
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
return model
for i in range(10):
model = build_model()
model.fit(x_train, y_train)
model.save_weights(f"./weights-{i}.hdf5")
And when you want to do the analysis:
for i in range(10):
model = build_model()
model.load_weights(f"./weights-{i}.hdf5")
do_analysis(model)
answered Dec 31 '18 at 17:38
Kasper FredenslundKasper Fredenslund
126113
126113
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53982255%2fhow-to-run-several-times-a-model-in-tensorflow%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown