{"id":200770,"date":"2020-11-23T00:40:30","date_gmt":"2020-11-22T16:40:30","guid":{"rendered":"http:\/\/4563.org\/?p=200770"},"modified":"2020-11-23T00:40:30","modified_gmt":"2020-11-22T16:40:30","slug":"tensorflow_macos-%e9%80%9f%e5%ba%a6%e6%b5%8b%e8%af%95","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=200770","title":{"rendered":"tensorflow_macos \u901f\u5ea6\u6d4b\u8bd5"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  tensorflow_macos \u901f\u5ea6\u6d4b\u8bd5               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : sharpy <\/span>  <span><i><\/i> 3<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>MBP16 i9-9880h 5500M 8G<\/p>\n<pre><code>#!\/usr\/bin\/env python # coding: utf-8 import tensorflow.compat.v2 as tf import tensorflow_datasets as tfds  tf.enable_v2_behavior()  from tensorflow.python.framework.ops import disable_eager_execution  disable_eager_execution()  from tensorflow.python.compiler.mlcompute import mlcompute  mlcompute.set_mlc_device(device_name='cpu')  (ds_train, ds_test), ds_info = tfds.load(     'mnist',     split=['train', 'test'],     shuffle_files=True,     as_supervised=True,     with_info=True, )   def normalize_img(image, label):     \"\"\"Normalizes images: `uint8` -&gt; `float32`.\"\"\"     return tf.cast(image, tf.float32) \/ 255., label   ds_train = ds_train.map(     normalize_img, num_parallel_calls=tf.data.experimental.AUTOTUNE) ds_train = ds_train.cache() ds_train = ds_train.shuffle(ds_info.splits['train'].num_examples) ds_train = ds_train.batch(128) ds_train = ds_train.prefetch(tf.data.experimental.AUTOTUNE)  ds_test = ds_test.map(     normalize_img, num_parallel_calls=tf.data.experimental.AUTOTUNE) ds_test = ds_test.batch(128) ds_test = ds_test.cache() ds_test = ds_test.prefetch(tf.data.experimental.AUTOTUNE)  model = tf.keras.models.Sequential([     tf.keras.layers.Flatten(input_shape=(28, 28, 1)),     tf.keras.layers.Dense(128, activation='relu'),     tf.keras.layers.Dense(10, activation='softmax') ]) model.compile(     loss='sparse_categorical_crossentropy',     optimizer=tf.keras.optimizers.Adam(0.001),     metrics=['accuracy'], )  model.fit(     ds_train,     epochs=10, ) <\/code><\/pre>\n<p>GPU \u901f\u5ea6<\/p>\n<p>Epoch 1\/10 469\/469 [==============================] &#8211; 10s 14ms\/step &#8211; batch: 234.0000 &#8211; size: 1.0000 &#8211; loss: 0.3598 &#8211; accuracy: 0.9028<\/p>\n<p>Epoch 2\/10 469\/469 [==============================] &#8211; 9s 14ms\/step &#8211; batch: 234.0000 &#8211; size: 1.0000 &#8211; loss: 0.1623 &#8211; accuracy: 0.9535<\/p>\n<p>Epoch 3\/10 469\/469 [==============================] &#8211; 9s 14ms\/step &#8211; batch: 234.0000 &#8211; size: 1.0000 &#8211; loss: 0.1182 &#8211; accuracy: 0.9664<\/p>\n<p>Epoch 4\/10 469\/469 [==============================] &#8211; 9s 14ms\/step &#8211; batch: 234.0000 &#8211; size: 1.0000 &#8211; loss: 0.0911 &#8211; accuracy: 0.9735<\/p>\n<p>Epoch 5\/10 469\/469 [==============================] &#8211; 9s 14ms\/step &#8211; batch: 234.0000 &#8211; size: 1.0000 &#8211; loss: 0.0732 &#8211; accuracy: 0.9786<\/p>\n<p>CPU \u901f\u5ea6<\/p>\n<p>Epoch 1\/10 469\/469 [==============================] &#8211; 3s 1ms\/step &#8211; batch: 234.0000 &#8211; size: 1.0000 &#8211; loss: nan &#8211; accuracy: 0.0987<\/p>\n<p>Epoch 2\/10 469\/469 [==============================] &#8211; 3s 1ms\/step &#8211; batch: 234.0000 &#8211; size: 1.0000 &#8211; loss: nan &#8211; accuracy: 0.0987<\/p>\n<p>Epoch 3\/10 469\/469 [==============================] &#8211; 3s 1ms\/step &#8211; batch: 234.0000 &#8211; size: 1.0000 &#8211; loss: nan &#8211; accuracy: 0.0987<\/p>\n<p>Epoch 4\/10 469\/469 [==============================] &#8211; 3s 1ms\/step &#8211; batch: 234.0000 &#8211; size: 1.0000 &#8211; loss: nan &#8211; accuracy: 0.0987<\/p>\n<p>Epoch 5\/10 469\/469 [==============================] &#8211; 3s 1ms\/step &#8211; batch: 234.0000 &#8211; size: 1.0000 &#8211; loss: nan &#8211; accuracy: 0.0987<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>6<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"4298538\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : tzm41 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6d45\u7a84\u7684 dense net\uff0cGPU \u6ca1\u5565\u52a0\u901f\u6548\u679c\u5427\u2026                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4298539\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : RichardSun <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u60f3\u8d77\u4e4b\u524d\u6211\u8bd5\u8fc7\u4e00\u4e2a\u597d\u50cf\u53eb plaidML \u7684 backend\uff0c\u968f\u4fbf\u8dd1\u4e86\u4e0b\u8bd5\u8bd5 GPU \u6a21\u5f0f\u6bd4\u666e\u901a backend \u7684 CPU \u90fd\u6162                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4298540\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ZRS <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8bd5\u8bd5 resnet50                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4298541\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : tianshilei1992 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6211\u4e00\u76f4\u60f3\u5199\u4e00\u4e2a Metal \u7684 OpenMP offloading plugin\uff0c\u4f46\u662f Metal compiler \u6ca1\u5f00\u6e90\uff0c\u6211\u641e\u4e0d\u5b9a CodeGen\u2026                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4298542\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : sharpy <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @tianshilei1992 #4 \u4f60\u53ef\u4ee5\u770b\u770b https:\/\/github.com\/a2flo\/floor.git \u8fd9\u4e2a\u9879\u76ee\uff0c\u4e5f\u8bb8\u6709\u70b9\u513f\u542f\u53d1\uff0c\u8fd9\u4e2a\u9879\u76ee\u4fee\u6539\u4e86 clang \u7684\u6e90\u7801\uff0c\u4f7f\u4e4b\u80fd\u751f\u6210\u5404\u4e2a\u540e\u7aef\u4ee3\u7801\uff0c\u770b\u8bf4\u660e\u662f\u201ccompiles compute\/graphics C++ code to CUDA\/PTX, Metal\/AIR, OpenCL\/SPIR\/SPIR-V, Vulkan\/SPIR-V code\/binaries \u201d                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4298543\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : tianshilei1992 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @sharpy                                                             <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>tensorflow_macos &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/200770"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=200770"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/200770\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=200770"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=200770"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=200770"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}