{"id":13454716,"url":"https://github.com/google/prettytensor","last_synced_at":"2025-03-24T06:31:17.976Z","repository":{"id":57454730,"uuid":"45413084","full_name":"google/prettytensor","owner":"google","description":"Pretty Tensor: Fluent Networks in TensorFlow","archived":true,"fork":false,"pushed_at":"2020-05-17T17:37:00.000Z","size":525,"stargazers_count":1237,"open_issues_count":28,"forks_count":151,"subscribers_count":66,"default_branch":"master","last_synced_at":"2024-05-08T21:33:23.247Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/google.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELIST.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE-2.0.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-11-02T18:19:46.000Z","updated_at":"2024-04-19T14:21:35.000Z","dependencies_parsed_at":"2022-09-05T05:41:01.757Z","dependency_job_id":null,"html_url":"https://github.com/google/prettytensor","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google%2Fprettytensor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google%2Fprettytensor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google%2Fprettytensor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google%2Fprettytensor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/google","download_url":"https://codeload.github.com/google/prettytensor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221939339,"owners_count":16904954,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T08:00:57.256Z","updated_at":"2024-10-28T21:31:08.071Z","avatar_url":"https://github.com/google.png","language":"Python","funding_links":[],"categories":["Models/Projects","Python","模型项目"],"sub_categories":["微信群"],"readme":"# Pretty Tensor - Fluent Neural Networks in TensorFlow\n\nPretty Tensor provides a high level builder API for TensorFlow. It provides\nthin wrappers on Tensors so that you can easily build multi-layer neural\nnetworks.\n\nPretty Tensor provides a set of objects that behave likes Tensors, but also\nsupport a chainable object syntax to quickly define neural networks\nand other layered architectures in TensorFlow.\n\n    result = (pretty_tensor.wrap(input_data, m)\n              .flatten()\n              .fully_connected(200, activation_fn=tf.nn.relu)\n              .fully_connected(10, activation_fn=None)\n              .softmax(labels, name=softmax_name))\n\nPlease look here for full documentation of the PrettyTensor object for all\navailable operations:\n[Available Operations](docs/PrettyTensor.md) or you can check out the [complete\ndocumentation](docs/pretty_tensor_top_level.md)\n\nSee the tutorial directory for samples:\n[tutorial/](prettytensor/tutorial/)\n\n## Installation\n\nThe easiest installation is just to use pip:\n\n1. Follow the instructions at\n    [tensorflow.org](https://www.tensorflow.org/versions/master/get_started/os_setup.html#pip_install)\n2. `pip install prettytensor`\n\n\n**Note:** Head is tested against the TensorFlow nightly builds and pip is tested against TensorFlow release.\n\n## Quick start\n\n### Imports\n    import prettytensor as pt\n    import tensorflow as tf\n\n### Setup your input\n    my_inputs = # numpy array of shape (BATCHES, BATCH_SIZE, DATA_SIZE)\n    my_labels = # numpy array of shape (BATCHES, BATCH_SIZE, CLASSES)\n    input_tensor = tf.placeholder(np.float32, shape=(BATCH_SIZE, DATA_SIZE))\n    label_tensor = tf.placeholder(np.float32, shape=(BATCH_SIZE, CLASSES))\n    pretty_input = pt.wrap(input_tensor)\n\n### Define your model\n    softmax, loss = (pretty_input.\n                     fully_connected(100).\n                     softmax_classifier(CLASSES, labels=label_tensor))\n\n### Train and evaluate\n    accuracy = softmax.evaluate_classifier(label_tensor)\n\n    optimizer = tf.train.GradientDescentOptimizer(0.1)  # learning rate\n    train_op = pt.apply_optimizer(optimizer, losses=[loss])\n\n    init_op = tf.initialize_all_variables()\n\n    with tf.Session() as sess:\n        sess.run(init_op)\n        for inp, label in zip(my_inputs, my_labels):\n            unused_loss_value, accuracy_value = sess.run([loss, accuracy],\n                                     {input_tensor: inp, label_tensor: label})\n            print 'Accuracy: %g' % accuracy_value\n\n## Features\n\n### Thin\n\n#### Full power of TensorFlow is easy to use\n\nPretty Tensors can be used (almost) everywhere that a tensor can.  Just call\n`pt.wrap` to make a tensor pretty.\n\nYou can also add any existing TensorFlow function to the chain using `apply`.\n`apply` applies the current Tensor as the first argument and takes all the other\narguments as normal.\n\n*Note:* because apply is so generic, Pretty Tensor doesn't try to wrap the\nworld.\n\n#### Plays well with other libraries\n\nIt also uses standard TensorFlow idioms so that it plays well with other\nlibraries, this means that you can use it a little bit in a model or throughout.\nJust make sure to run the update_ops on each training set\n(see [with_update_ops](docs/pretty_tensor_top_level.md#with_update_ops)).\n\n### Terse\n\nYou've already seen how a Pretty Tensor is chainable and you may have noticed\nthat it takes care of handling the input shape.  One other feature worth noting\nare defaults.  Using defaults you can specify reused values in a single place\nwithout having to repeat yourself.\n\n    with pt.defaults_scope(activation_fn=tf.nn.relu):\n      hidden_output2 = (pretty_images.flatten()\n                       .fully_connected(100)\n                       .fully_connected(100))\n\nCheck out the documentation to see\n[all supported defaults](docs/pretty_tensor_top_level.md#defaults_scope).\n\n### Code matches model\n\nSequential mode lets you break model construction across lines and provides\nthe subdivide syntactic sugar that makes it easy to define and understand\ncomplex structures like an [inception module](http://arxiv.org/abs/1409.4842):\n\n\n    with pretty_tensor.defaults_scope(activation_fn=tf.nn.relu):\n      seq = pretty_input.sequential()\n      with seq.subdivide(4) as towers:\n        towers[0].conv2d(1, 64)\n        towers[1].conv2d(1, 112).conv2d(3, 224)\n        towers[2].conv2d(1, 32).conv2d(5, 64)\n        towers[3].max_pool(2, 3).conv2d(1, 32)\n\n![Inception module showing branch and rejoin](inception_module.png)\n\nTemplates provide guaranteed parameter reuse and make unrolling recurrent\nnetworks easy:\n\n    output = [], s = tf.zeros([BATCH, 256 * 2])\n\n    A = (pretty_tensor.template('x')\n         .lstm_cell(num_units=256, state=UnboundVariable('state'))\n\n    for x in pretty_input_array:\n      h, s = A.construct(x=x, state=s)\n      output.append(h)\n\nThere are also some convenient shorthands for LSTMs and GRUs:\n\n    pretty_input_array.sequence_lstm(num_units=256)\n\n![Unrolled RNN](unrolled_lstm.png)\n\n### Extensible\n\nYou can call any existing operation by using `apply` and it will simply\nsubsitute the current tensor for the first argument.\n\n    pretty_input.apply(tf.mul, 5)\n\nYou can also create a new operation  There are two supported registration\nmechanisms to add your own functions. `@Register()` allows you to create a\nmethod on PrettyTensor that operates on the Tensors and returns either a loss or\na new value. Name scoping and variable scoping are handled by the framework.\n\nThe following method adds the leaky_relu method to every Pretty Tensor:\n\n    @pt.Register\n    def leaky_relu(input_pt):\n      return tf.select(tf.greater(input_pt, 0.0), input_pt, 0.01 * input_pt)\n\n\n`@RegisterCompoundOp()` is like adding a macro, it is designed to group together\ncommon sets of operations.\n\n### Safe variable reuse\n\nWithin a graph, you can reuse variables by using templates.  A template is\njust like a regular graph except that some variables are left unbound.\n\nSee more details in [PrettyTensor class](docs/PrettyTensor.md).\n\n### Accessing Variables\n\nPretty Tensor uses the standard graph collections from TensorFlow to store variables.  These can be accessed using `tf.get_collection(key)` with the following keys:\n\n* `tf.GraphKeys.VARIABLES`: all variables that should be saved (including some statistics).\n* `tf.GraphKeys.TRAINABLE_VARIABLES: all variables that can be trained (including those before a `stop_gradients` call). These are what would typically be called *parameters* of the model in ML parlance.\n* `pt.GraphKeys.TEST_VARIABLES`: variables used to evaluate a model. These are typically not saved and are reset by the LocalRunner.evaluate method to get a fresh evaluation.\n\n## Authors\n\nEider Moore (eiderman)\n\nwith key contributions from:\n\n* Hubert Eichner\n* Oliver Lange\n* Sagar Jain (sagarjn)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoogle%2Fprettytensor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgoogle%2Fprettytensor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoogle%2Fprettytensor/lists"}