Skip to content

Instantly share code, notes, and snippets.

View backnotprop's full-sized avatar
📟
E.Alderson

Michael Ramos backnotprop

📟
E.Alderson
View GitHub Profile
private let models = [
wave().model,
udnie().model,
rain_princess().model,
la_muse().model
]
import coremltools
def convert_multiarray_output_to_image(spec, feature_name, is_bgr=False):
"""
Convert an output multiarray to be represented as an image
This will modify the Model_pb spec passed in.
Example:
model = coremltools.models.MLModel('MyNeuralNetwork.mlmodel')
spec = model.get_spec()
convert_multiarray_output_to_image(spec,'imageOutput',is_bgr=False)
import tfcoreml as tf_converter
tf_converter.convert(tf_model_path = 'output_graph.pb',
mlmodel_path = 'model_name.mlmodel',
output_feature_names = ['add_37:0'],
## Note found this after running a conversion the first time
image_input_names = ['img_placeholder__0'])
# tfcoreml src
# file1 : _interpret_shapes.py
#
# in the _SHAPE_TRANSLATOR_REGISTRY we need to add the Pow operation
_SHAPE_TRANSLATOR_REGISTRY = {
... previous keys ...
# add this:
'Pow': _identity,
}
# function ffwd, line 98
# https://github.com/lengstrom/fast-style-transfer/blob/master/evaluate.py#L98
if os.path.isdir(checkpoint_dir):
ckpt = tf.train.get_checkpoint_state(checkpoint_dir)
if ckpt and ckpt.model_checkpoint_path:
saver.restore(sess, ckpt.model_checkpoint_path)
########## add this for pre-trained models ###########
frozen_graph_def = tf.graph_util.convert_variables_to_constants(sess,sess.graph_def,['add_37'])
with open('output_graph.pb', 'wb') as f:
f.write(frozen_graph_def.SerializeToString())
# function ffwd,line 93
# https://github.com/lengstrom/fast-style-transfer/blob/master/evaluate.py#L93
preds = transform.net(img_placeholder)
# !! Add This !!
print(preds)
/**
* Cyclic Elimination Stage 3
* - description needed
*/
function _cycleReduceStage() {
let stable = false;
// all or nothing phase
while(!stable) {
// there is a start if any one person has more than 1 preference remaining
let start = indexWithMultipleRemain();
/**
* Elimination Stage 2
* - removes all preferences in a list who can not be possibly matched
*/
function _eliminateStage() {
_.forIn(_DB, (person,id) => {
let keepLast = _.findIndex(person.choices, function(p) { return p.id == person.acceptedReceivedID; });
for(let i = keepLast + 1; i < person.choices.length; i++) {
// each the rejected and rejecter can remove each other from choices list
eliminateChoices(person, _DB[person.choices[i].id]);
// eliminates two people from each others preference list
function eliminateChoices(rejecter, rejected) {
let remove1 = _.findIndex(rejected.choices, function(p) { return p.id == rejecter.id; });
rejected.choices.splice(remove1, 1);
let remove2 = _.findIndex(rejecter.choices, function(p) { return p.id == rejected.id; });
rejecter.choices.splice(remove2, 1);
}
// sender has accepted sent, receiver has accepted received
function acceptOffer(sender,receiver, receiverRank, senderRank) {
sender.hasAcceptedSentProposal = true;
sender.acceptedSentRank = receiverRank;
sender.acceptedSentID = receiver.id;
receiver.hasAcceptedReceivedProposal = true;
receiver.acceptedReceivedRank = senderRank;
receiver.acceptedReceivedID = sender.id;
}