avatarTensorFlow

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

4092

Abstract

 <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*8iqpjzLeJ117LVUJ4ormMQ.jpeg)"></div>
          </div>
        </div>
      </a>
    </div><p id="96ef">It has white bezels. Bad for pros, we’re told. An absolute nightmare when it comes to reflections, colour judgement and the ability to cocoon yourself within your creative work. Or is it?</p><p id="3a92">In my experience, the concerns over the white bezels don’t manifest themselves quite so readily — and this brings me back to that missing Apple logo.</p><p id="6c56">Apple wants the iMac to ‘disappear’ when you’re using it. This enables their all-in-one to fit “in more places than ever”, according to their marketing team but also delivers a superb user experience that even the outgoing model struggled to deliver.</p><p id="3444">The white bezels, ultra-thin design, colour-matched chin and lack of the Apple logo leaves you with one thing to focus on: that beautiful screen. It’s a disappearing trick quite unlike any other, and while the concern over the colour choice for those bezels is entirely relevant if you’re someone who works with imagery, it appears to deliver the ultimate computing experience for everything else.</p><p id="74e7">A quick note on the colour, too. I went for the blue version, and it’s a lovely, deep, rich hue. So lovely, in fact, that I wish I could see the back of my iMac more readily; this is a device that demands to be seen from all angles if you can position it in that way.</p><h2 id="6f4c">The guts</h2><figure id="0e4d"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*d6r41PiSarlMHMOG.jpg"><figcaption>Image courtesy of author</figcaption></figure><p id="0f20">The new iMac <a href="https://markellisreviews.com/m1-mac-mini-or-m1-imac/">is basically an M1 Mac mini</a> shoved into a very nice screen.</p><div id="d5fb" class="link-block">
      <a href="https://readmedium.com/whats-best-m1-mac-mini-or-m1-imac-ed20ded4650c">
        <div>
          <div>
            <h2>What’s Best: M1 Mac mini or M1 iMac?</h2>
            <div><h3>The battle has begun</h3></div>
            <div><p>medium.com</p></div>
          </div>
          <div>
            <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*E2KXw4T6-B6gqTF3LGWvkw.png)"></div>
          </div>
        </div>
      </a>
    </div><p id="249e">The beauty of this combination and the market at which the iMac is aimed means you can buy a computer for your home that will make mincemeat of literally any normal task you throw at it while retaining enough power to enable more intensive work if anyone fancies it.</p><p id="a818">So, if you only need to use it for email, a bit of web browsing and throwing together the odd PowerPoint presentation, it’ll be the best computer you’ve used for the task. But if your daughter fancies dipping her hand into software development and your son decides to give video editing a try, the iMac will serve them perfectly, too.</p><p id="536c">Yes, even with 8GB of RAM.</p><p id="f343">This is the brilliance of the M1 chip. It’s like an ultra-high performance car which is also a cinch to drive to the supermarket. It can either be no-frills or highly performant, without either ability getting in the way of the other.</p><p id="f080">There are some odd spec choices, though. The 7/8-core GPU option remains (ignore this — RAM and storage upgrades are the only decisions worthy of your brainpower), and in order to get the maximum number of ports (the base model only comes with two), you need to spend more. The goes, inexplicably, for some of the colour options.</p><p id="2e2d">My <a href="https://markellisreviews.com/8gb-vs-16gb-m1-macbook-does-it-even-matter/">advice for the choice of RAM remains</a>, but whether you opt for the base spec iMac (the version I have) or a souped-up 16GB version with 2TB of storage, you’ll be happy with your purchase. Just buy as much as you can afford and enjoy the damn thing.</p><h2 id="67b1">The

Options

screen</h2><figure id="756d"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*K6Bjq3kPe1VH8EWf.jpg"><figcaption>Image courtesy of author</figcaption></figure><p id="daab">The 4.5K P3 retina screen on this new iMac is wonderful. But that was always going to be the case.</p><p id="0389">You cannot get a screen as good as this for the same money. Comparing the price of the iMac to the M1 Mac mini, you’re paying about £600/$600 for the screen. Show me a third-party panel that matches it, pixel-for-pixel.</p><p id="a0d6">In fact, don’t waste your time. There isn’t one.</p><div id="bb02" class="link-block"> <a href="https://readmedium.com/could-the-next-imac-tempt-me-away-from-my-ultra-wide-monitor-6366d93bc9d2"> <div> <div> <h2>Could the Next iMac Tempt Me Away From My Ultra-Wide Monitor?</h2> <div><h3>What does it mean for the M1 Mac mini?!</h3></div> <div><p>medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*0YJ9V2g3No3RDwoUEX-3sg.jpeg)"></div> </div> </div> </a> </div><p id="d343">I switched to an ultra-wide 34" monitor when the Mac mini became my daily workhorse. This was a marvellous decision, but now that I’m running a long-term test on the new iMac, I’ve had to relegate both the Mac mini and the huge screen to which it is attached to a video editing station. Everything else is being carried out on the iMac.</p><p id="e181">This has taken some getting used to. The 24" screen is a lot smaller than the MSI ultra-wide, but what it lacks in screen real estate, it obviously makes up for in sharpness, colour depth and brightness. And, in fact, there’s something rather refreshing about switching to a smaller screen; it keeps me focused on one task at a time, which is no bad thing.</p><h2 id="a265">Conclusion</h2><figure id="871a"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*fGRzEVX2zIwB8GMk.jpg"><figcaption>Image courtesy of author</figcaption></figure><p id="f7df">This isn’t the most in-depth review I’ve written, but it didn’t need to be. I’ve waxed lyrical about the M1 chip for months, and it once again sits at the heart of the story here.</p><div id="8db3" class="link-block"> <a href="https://readmedium.com/why-the-m1-imac-makes-total-sense-88c2d2820946"> <div> <div> <h2>Why the M1 iMac Makes Total Sense</h2> <div><h3>And why I love the design</h3></div> <div><p>medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*cQGlCegDGzlJwI8rRa6V7w.png)"></div> </div> </div> </a> </div><p id="78c4">I can’t think of another home computer which offers the same level of performance and screen quality at this price point. Unless you’re a die-hard Windows person, there’s no reason to look beyond the iMac if you have some money to spend and want an awesome computer for everyone at home.</p><p id="d5bc">Equally, if you’re a small business owner, the new iMac is a brilliant investment — particularly if the aesthetics of the machine are important to you.</p><p id="f342">The iMac I’m really hankering after is the replacement for the Intel-based 27" 5K version. I guess we’ll see that later this year, but the effortlessness, design perfection and masterful grasp of its target market turn the 24" iMac into a tantalising glimpse at what we have in store beyond this first iteration.</p><p id="334e">I cannot wait.</p><h2 id="fcad">Before you go</h2><p id="a54e"><a href="https://markellisreviews.ck.page/newsletter"><b>Join my behind-the-scenes mailing list</b></a></p><p id="bdcc"><i>Originally published at <a href="https://markellisreviews.com/imac-24-m1-first-impressions/">https://markellisreviews.com</a> on May 25, 2021.</i></p></article></body>

Effective TensorFlow 2.0: Best Practices and What’s Changed

Posted by the TensorFlow Team

In a recent article, we mentioned that TensorFlow 2.0 has been redesigned with a focus on developer productivity, simplicity, and ease of use.

To take a closer look at what’s changed, and to learn about best practices, check out the new Effective TensorFlow 2.0 guide (published on GitHub). This article provides a quick summary of the content you’ll find there. If any of these topics interest you, head to the guide to learn more!

A brief summary of major changes

There are many changes in TensorFlow 2.0 to make users more productive, including removing redundant APIs, making APIs more consistent (Unified RNNs, Unified Optimizers), and better integrating with the Python runtime with Eager execution.

Many RFCs (check them out, if you’re new to them!) have explained the changes and thinking that have gone into making TensorFlow 2.0. This guide presents a vision for what development in TensorFlow 2.0 should look like. It’s assumed you have some familiarity with TensorFlow 1.x.

API Cleanup

Many APIs are either gone or moved in TF 2.0, and some have been replaced with their 2.0 equivalents — tf.summary, tf.keras.metrics, and tf.keras.optimizers. The easiest way to automatically apply these renames is to use the v2 upgrade script.

Eager execution

TensorFlow 1.X requires users to manually stitch together an abstract syntax tree (the graph) by making tf.* API calls. It then requires users to manually compile the abstract syntax tree by passing a set of output tensors and input tensors to a session.run() call. By contrast, TensorFlow 2.0 executes eagerly (like Python normally does) and in 2.0, graphs and sessions should feel like implementation details.

No more globals

TensorFlow 1.X relied heavily on implicitly global namespaces. When you called tf.Variable(), it would be put into the default graph, and it would remain there, even if you lost track of the Python variable pointing to it. You could then recover that tf.Variable, but only if you knew the name that it had been created with. This was difficult to do if you were not in control of the variable’s creation. As a result, all sorts of mechanisms proliferated to attempt to help users find their variables again.

TensorFlow 2.0 eliminates all of these mechanisms (Variables 2.0 RFC) in favor of the default mechanism: Keep track of your variables! If you lose track of a tf.Variable, it gets garbage collected. See the guide for more details.

Functions, not sessions

A session.run() call is almost like a function call: You specify the inputs and the function to be called, and you get back a set of outputs. In TensorFlow 2.0, you can decorate a Python function using tf.function() to mark it for JIT compilation so that TensorFlow runs it as a single graph (Functions 2.0 RFC).

This mechanism allows TensorFlow 2.0 to gain all of the benefits of graph mode:

  • Performance: The function can be optimized (node pruning, kernel fusion, etc.)
  • Portability: The function can be exported/reimported (SavedModel 2.0 RFC), allowing users to reuse and share modular TensorFlow functions.

With the power to freely intersperse Python and TensorFlow code, you can take full advantage of Python’s expressiveness. But portable TensorFlow executes in contexts without a Python interpreter — mobile, C++, and JS. To help users avoid having to rewrite their code when adding @tf.function, AutoGraph will convert a subset of Python constructs into their TensorFlow equivalents.

See the guide for more details.

Recommendations for idiomatic TensorFlow 2.0

Refactor your code into smaller functions

A common usage pattern in TensorFlow 1.X was the “kitchen sink” strategy, where the union of all possible computations was preemptively laid out, and then selected tensors were evaluated via session.run(). In TensorFlow 2.0, users should refactor their code into smaller functions which are called as needed. In general, it’s not necessary to decorate each of these smaller functions with tf.function; only use tf.function to decorate high-level computations — for example, one step of training, or the forward pass of your model.

Use Keras layers and models to manage variables

Keras models and layers offer the convenient variables and trainable_variables properties, which recursively gather up all dependent variables. This makes it easy to manage variables locally to where they are being used.

Keras layers/models inherit from tf.train.Checkpointable and are integrated with @tf.function, which makes it possible to directly checkpoint or export SavedModels from Keras objects. You do not necessarily have to use Keras’s.fit() API to take advantage of these integrations.

See the guide for more details.

Combine tf.data.Datasets and @tf.function

When iterating over training data that fits in memory, feel free to use regular Python iteration. Otherwise, tf.data.Dataset is the best way to stream training data from disk. Datasets are iterables (not iterators), and work just like other Python iterables in Eager mode. You can fully utilize dataset async prefetching/streaming features by wrapping your code in tf.function(), which replaces Python iteration with the equivalent graph operations using AutoGraph.

@tf.function
def train(model, dataset, optimizer):
 for x, y in dataset:
  with tf.GradientTape() as tape:
   prediction = model(x)
   loss = loss_fn(prediction, y)
  gradients = tape.gradients(loss, model.trainable_variables)
  optimizer.apply_gradients(gradients, model.trainable_variables)

If you use the Keras .fit() API, you won’t have to worry about dataset iteration.

model.compile(optimizer=optimizer, loss=loss_fn)
model.fit(dataset)

Take advantage of AutoGraph with Python control flow

AutoGraph provides a way to convert data-dependent control flow into graph-mode equivalents like tf.cond and tf.while_loop.

One common place where data-dependent control flow appears is in sequence models. tf.keras.layers.RNN wraps an RNN cell, allowing you to either statically or dynamically unroll the recurrence. For demonstration’s sake, you could reimplement dynamic unroll as follows:

class DynamicRNN(tf.keras.Model):
def __init__(self, rnn_cell):
 super(DynamicRNN, self).__init__(self)
 self.cell = rnn_cell
def call(self, input_data):
 # [batch, time, features] -> [time, batch, features]
 input_data = tf.transpose(input_data, [1, 0, 2])
 outputs = tf.TensorArray(tf.float32, input_data.shape[0])
 state = self.cell.zero_state(input_data.shape[1], dtype=tf.float32)
 for i in tf.range(input_data.shape[0]):
  output, state = self.cell(input_data[i], state)
  outputs = outputs.write(i, output)
 return tf.transpose(outputs.stack(), [1, 0, 2]), state

See the guide for more details.

Use tf.metrics to aggregate data and tf.summary to log it

Finally, a complete set of tf.summary symbols are coming soon. You can access the 2.0 version of tf.summary with:

from tensorflow.python.ops import summary_ops_v2

See the guide for more details.

Next steps

This article provided a quick summary of the Effective TF 2.0 Guide (if you’re interested in these topics, head there to learn more!) To learn more about TensorFlow 2.0, we also recommend these recent articles:

And please tune in for the TensorFlow developer summit on March 6th and 7th. As always, all the talks will be uploaded to YouTube for folks who can’t make it in person.

TensorFlow
Announcements
Keras
Tf2
Recommended from ReadMedium