You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

tf04_function_and_auto_graph.ipynb 18 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "code",
  5. "execution_count": 1,
  6. "metadata": {},
  7. "outputs": [
  8. {
  9. "name": "stdout",
  10. "output_type": "stream",
  11. "text": [
  12. "2.2.0\n",
  13. "sys.version_info(major=3, minor=6, micro=9, releaselevel='final', serial=0)\n",
  14. "matplotlib 3.3.4\n",
  15. "numpy 1.19.5\n",
  16. "pandas 1.1.5\n",
  17. "sklearn 0.24.2\n",
  18. "tensorflow 2.2.0\n",
  19. "tensorflow.keras 2.3.0-tf\n"
  20. ]
  21. }
  22. ],
  23. "source": [
  24. "import matplotlib as mpl\n",
  25. "import matplotlib.pyplot as plt\n",
  26. "%matplotlib inline\n",
  27. "import numpy as np\n",
  28. "import sklearn\n",
  29. "import pandas as pd\n",
  30. "import os\n",
  31. "import sys\n",
  32. "import time\n",
  33. "import tensorflow as tf\n",
  34. "\n",
  35. "from tensorflow import keras\n",
  36. "\n",
  37. "print(tf.__version__)\n",
  38. "print(sys.version_info)\n",
  39. "for module in mpl, np, pd, sklearn, tf, keras:\n",
  40. " print(module.__name__, module.__version__)"
  41. ]
  42. },
  43. {
  44. "cell_type": "code",
  45. "execution_count": 2,
  46. "metadata": {},
  47. "outputs": [
  48. {
  49. "name": "stdout",
  50. "output_type": "stream",
  51. "text": [
  52. "tf.Tensor(-0.95021296, shape=(), dtype=float32)\n",
  53. "tf.Tensor([-0.95021296 -0.917915 ], shape=(2,), dtype=float32)\n",
  54. "tf.Tensor(-0.95021296, shape=(), dtype=float32)\n",
  55. "tf.Tensor([-0.95021296 -0.917915 ], shape=(2,), dtype=float32)\n",
  56. "True\n",
  57. "<function scaled_elu at 0x7f971c419268>\n",
  58. "<tensorflow.python.eager.def_function.Function object at 0x7f971c408e48>\n"
  59. ]
  60. }
  61. ],
  62. "source": [
  63. "# tf.function and auto-graph.\n",
  64. "#自己实现一下elu激活函数,如果scale不为1,那就是selu\n",
  65. "def scaled_elu(z, scale=1.0, alpha=1.0):\n",
  66. " # z >= 0 ? scale * z : scale * alpha * tf.nn.elu(z)\n",
  67. " is_positive = tf.greater_equal(z, 0.0)\n",
  68. "# return scale * tf.where(is_positive, z, alpha * tf.nn.elu(z))\n",
  69. " return scale * tf.where(is_positive, z, alpha * (tf.math.exp(z)-1))\n",
  70. "\n",
  71. "#运行一下,这还是py函数\n",
  72. "print(scaled_elu(tf.constant(-3.)))\n",
  73. "print(scaled_elu(tf.constant([-3., -2.5])))\n",
  74. "\n",
  75. "#把py实现的函数变为图实现的函数\n",
  76. "#scaled_elu_tf就是图\n",
  77. "scaled_elu_tf = tf.function(scaled_elu)\n",
  78. "print(scaled_elu_tf(tf.constant(-3.)))\n",
  79. "print(scaled_elu_tf(tf.constant([-3., -2.5])))\n",
  80. "\n",
  81. "#可以通过这种方式找回原来的py函数\n",
  82. "print(scaled_elu_tf.python_function is scaled_elu)\n",
  83. "print(scaled_elu)\n",
  84. "print(scaled_elu_tf)#tf的函数的执行效率比较高"
  85. ]
  86. },
  87. {
  88. "cell_type": "code",
  89. "execution_count": 5,
  90. "metadata": {},
  91. "outputs": [
  92. {
  93. "name": "stdout",
  94. "output_type": "stream",
  95. "text": [
  96. "1.03 s ± 25.4 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
  97. "868 ms ± 6.27 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
  98. ]
  99. }
  100. ],
  101. "source": [
  102. "#我们来测试一下性能,100万个数\n",
  103. "%timeit scaled_elu(tf.random.normal((10000, 10000)))\n",
  104. "%timeit scaled_elu_tf(tf.random.normal((10000, 10000)))"
  105. ]
  106. },
  107. {
  108. "cell_type": "code",
  109. "execution_count": 4,
  110. "metadata": {},
  111. "outputs": [
  112. {
  113. "name": "stdout",
  114. "output_type": "stream",
  115. "text": [
  116. "<tensorflow.python.eager.def_function.Function object at 0x7f7f1051d780>\n",
  117. "tf.Tensor(1.9999981, shape=(), dtype=float32)\n"
  118. ]
  119. }
  120. ],
  121. "source": [
  122. "# 1 + 1/2 + 1/2^2 + ... + 1/2^n\n",
  123. "#加了@tf.function装饰后就变为图结果,但是输入类型上不会有变化\n",
  124. "@tf.function\n",
  125. "def converge_to_2(n_iters):\n",
  126. " total = tf.constant(0.)\n",
  127. " increment = tf.constant(1.)\n",
  128. " for _ in range(n_iters):\n",
  129. " total += increment\n",
  130. " increment /= 2.0\n",
  131. " return total\n",
  132. "print(converge_to_2)\n",
  133. "print(converge_to_2(20))"
  134. ]
  135. },
  136. {
  137. "cell_type": "code",
  138. "execution_count": 5,
  139. "metadata": {},
  140. "outputs": [],
  141. "source": [
  142. "#如何看tf的图的代码\n",
  143. "def display_tf_code(func):\n",
  144. " code = tf.autograph.to_code(func)\n",
  145. " from IPython.display import display, Markdown\n",
  146. " display(Markdown('```python\\n{}\\n```'.format(code)))"
  147. ]
  148. },
  149. {
  150. "cell_type": "code",
  151. "execution_count": 6,
  152. "metadata": {},
  153. "outputs": [
  154. {
  155. "data": {
  156. "text/markdown": [
  157. "```python\n",
  158. "def tf__scaled_elu(z, scale=None, alpha=None):\n",
  159. " do_return = False\n",
  160. " retval_ = ag__.UndefinedReturnValue()\n",
  161. " with ag__.FunctionScope('scaled_elu', 'fscope', ag__.ConversionOptions(recursive=True, user_requested=True, optional_features=(), internal_convert_user_code=True)) as fscope:\n",
  162. " is_positive = ag__.converted_call(tf.greater_equal, (z, 0.0), None, fscope)\n",
  163. " try:\n",
  164. " do_return = True\n",
  165. " retval_ = fscope.mark_return_value((scale * ag__.converted_call(tf.where, (is_positive, z, (alpha * (ag__.converted_call(tf.math.exp, (z,), None, fscope) - 1))), None, fscope)))\n",
  166. " except:\n",
  167. " do_return = False\n",
  168. " raise\n",
  169. " (do_return,)\n",
  170. " return ag__.retval(retval_)\n",
  171. "\n",
  172. "```"
  173. ],
  174. "text/plain": [
  175. "<IPython.core.display.Markdown object>"
  176. ]
  177. },
  178. "metadata": {},
  179. "output_type": "display_data"
  180. }
  181. ],
  182. "source": [
  183. "#传普通py函数,返回的是tf图的代码\n",
  184. "display_tf_code(scaled_elu)"
  185. ]
  186. },
  187. {
  188. "cell_type": "code",
  189. "execution_count": 9,
  190. "metadata": {},
  191. "outputs": [
  192. {
  193. "data": {
  194. "text/markdown": [
  195. "```python\n",
  196. "def tf__converge_to_2(n_iters):\n",
  197. " do_return = False\n",
  198. " retval_ = ag__.UndefinedReturnValue()\n",
  199. " with ag__.FunctionScope('converge_to_2', 'fscope', ag__.ConversionOptions(recursive=True, user_requested=True, optional_features=(), internal_convert_user_code=True)) as fscope:\n",
  200. " total = ag__.converted_call(tf.constant, (0.0,), None, fscope)\n",
  201. " increment = ag__.converted_call(tf.constant, (1.0,), None, fscope)\n",
  202. "\n",
  203. " def get_state():\n",
  204. " return (total, increment)\n",
  205. "\n",
  206. " def set_state(loop_vars):\n",
  207. " nonlocal total, increment\n",
  208. " (total, increment) = loop_vars\n",
  209. "\n",
  210. " def loop_body(itr):\n",
  211. " nonlocal total, increment\n",
  212. " _ = itr\n",
  213. " total += increment\n",
  214. " increment /= 2.0\n",
  215. " ag__.for_stmt(ag__.converted_call(range, (n_iters,), None, fscope), None, loop_body, get_state, set_state, ('total', 'increment'), {})\n",
  216. " try:\n",
  217. " do_return = True\n",
  218. " retval_ = fscope.mark_return_value(total)\n",
  219. " except:\n",
  220. " do_return = False\n",
  221. " raise\n",
  222. " (do_return,)\n",
  223. " return ag__.retval(retval_)\n",
  224. "\n",
  225. "```"
  226. ],
  227. "text/plain": [
  228. "<IPython.core.display.Markdown object>"
  229. ]
  230. },
  231. "metadata": {},
  232. "output_type": "display_data"
  233. }
  234. ],
  235. "source": [
  236. "#这个的前提是去除converge_to_2的装饰\n",
  237. "# 因为converge_to_2有@tf.function标注,去掉应该就没问题了。to_code函数的输入是module,\n",
  238. "# class, method, function, traceback, frame, or code object。不能是tf function.\n",
  239. "display_tf_code(converge_to_2.python_function)"
  240. ]
  241. },
  242. {
  243. "cell_type": "code",
  244. "execution_count": 10,
  245. "metadata": {},
  246. "outputs": [
  247. {
  248. "name": "stdout",
  249. "output_type": "stream",
  250. "text": [
  251. "tf.Tensor(21.0, shape=(), dtype=float32)\n"
  252. ]
  253. }
  254. ],
  255. "source": [
  256. "#tf要把变量定义在函数外面,不能放里边\n",
  257. "var = tf.Variable(0.)\n",
  258. "\n",
  259. "@tf.function\n",
  260. "def add_21():\n",
  261. " return var.assign_add(21) # += \n",
  262. "\n",
  263. "print(add_21())"
  264. ]
  265. },
  266. {
  267. "cell_type": "code",
  268. "execution_count": 12,
  269. "metadata": {},
  270. "outputs": [
  271. {
  272. "name": "stdout",
  273. "output_type": "stream",
  274. "text": [
  275. "Python inputs incompatible with input_signature:\n",
  276. " inputs: (\n",
  277. " tf.Tensor([1. 2. 3.], shape=(3,), dtype=float32))\n",
  278. " input_signature: (\n",
  279. " TensorSpec(shape=(None,), dtype=tf.int32, name='x'))\n",
  280. "--------------------------------------------------\n",
  281. "tf.Tensor([ 1 8 27], shape=(3,), dtype=int32)\n",
  282. "<tensorflow.python.eager.def_function.Function object at 0x7f7e3ef13fd0>\n"
  283. ]
  284. }
  285. ],
  286. "source": [
  287. "#cube计算立方,py是泛型设计,我们通过input_signature加类型限制可以防止调错\n",
  288. "# @tf.function(input_signature=[tf.TensorSpec([None], tf.int32, name='x')])\n",
  289. "@tf.function\n",
  290. "def cube(z):\n",
  291. " return tf.pow(z, 3)\n",
  292. "\n",
  293. "try:\n",
  294. " print(cube(tf.constant([1., 2., 3.])))\n",
  295. "except ValueError as ex:\n",
  296. " print(ex)\n",
  297. "\n",
  298. "print('-'*50)\n",
  299. "#这行没问题\n",
  300. "print(cube(tf.constant([1, 2, 3])))\n",
  301. "print(cube)"
  302. ]
  303. },
  304. {
  305. "cell_type": "code",
  306. "execution_count": 13,
  307. "metadata": {},
  308. "outputs": [
  309. {
  310. "ename": "ValueError",
  311. "evalue": "invalid literal for int() with base 10: 'abc'",
  312. "output_type": "error",
  313. "traceback": [
  314. "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
  315. "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
  316. "\u001b[0;32m<ipython-input-13-1e11daa61250>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'abc'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
  317. "\u001b[0;31mValueError\u001b[0m: invalid literal for int() with base 10: 'abc'"
  318. ]
  319. }
  320. ],
  321. "source": [
  322. "int('abc')"
  323. ]
  324. },
  325. {
  326. "cell_type": "code",
  327. "execution_count": 16,
  328. "metadata": {},
  329. "outputs": [
  330. {
  331. "name": "stdout",
  332. "output_type": "stream",
  333. "text": [
  334. "<tensorflow.python.eager.function.ConcreteFunction object at 0x7f7edb682e48>\n",
  335. "<tensorflow.python.eager.def_function.Function object at 0x7f7e3ef13fd0>\n",
  336. "tf.Tensor([ 1 8 27], shape=(3,), dtype=int32)\n"
  337. ]
  338. }
  339. ],
  340. "source": [
  341. "# @tf.function py func -> tf graph\n",
  342. "# get_concrete_function -> 给tf.function add input signature -> SavedModel\n",
  343. "\n",
  344. "cube_func_int32 = cube.get_concrete_function(\n",
  345. " tf.TensorSpec([None], tf.int32))\n",
  346. "print(cube_func_int32)\n",
  347. "print(cube)\n",
  348. "\n",
  349. "try:\n",
  350. " print(cube_func_int32(tf.constant([1, 2, 3])))\n",
  351. "except Exception as ex:\n",
  352. " print(ex)"
  353. ]
  354. },
  355. {
  356. "cell_type": "code",
  357. "execution_count": 17,
  358. "metadata": {},
  359. "outputs": [
  360. {
  361. "name": "stdout",
  362. "output_type": "stream",
  363. "text": [
  364. "<tensorflow.python.eager.function.ConcreteFunction object at 0x7f7edb682e48>\n",
  365. "<tensorflow.python.eager.function.ConcreteFunction object at 0x7f7edb682e48>\n",
  366. "True\n"
  367. ]
  368. }
  369. ],
  370. "source": [
  371. "#我们只要看原来函数和新生成的是否一致\n",
  372. "# print(cube_func_int32 is cube.get_concrete_function())\n",
  373. "print(cube.get_concrete_function(\n",
  374. " tf.constant([1, 2, 3])))\n",
  375. "print(cube_func_int32)\n",
  376. "print(cube_func_int32 is cube.get_concrete_function(\n",
  377. " tf.constant([1, 2, 3])))"
  378. ]
  379. },
  380. {
  381. "cell_type": "code",
  382. "execution_count": 18,
  383. "metadata": {},
  384. "outputs": [
  385. {
  386. "name": "stdout",
  387. "output_type": "stream",
  388. "text": [
  389. "<tensorflow.python.eager.function.ConcreteFunction object at 0x7f7edb682e48>\n"
  390. ]
  391. },
  392. {
  393. "data": {
  394. "text/plain": [
  395. "<tensorflow.python.framework.func_graph.FuncGraph at 0x7f7e3ef7bef0>"
  396. ]
  397. },
  398. "execution_count": 18,
  399. "metadata": {},
  400. "output_type": "execute_result"
  401. }
  402. ],
  403. "source": [
  404. "print(cube_func_int32)\n",
  405. "cube_func_int32.graph"
  406. ]
  407. },
  408. {
  409. "cell_type": "code",
  410. "execution_count": 19,
  411. "metadata": {},
  412. "outputs": [
  413. {
  414. "data": {
  415. "text/plain": [
  416. "[<tf.Operation 'x' type=Placeholder>,\n",
  417. " <tf.Operation 'Pow/y' type=Const>,\n",
  418. " <tf.Operation 'Pow' type=Pow>,\n",
  419. " <tf.Operation 'Identity' type=Identity>]"
  420. ]
  421. },
  422. "execution_count": 19,
  423. "metadata": {},
  424. "output_type": "execute_result"
  425. }
  426. ],
  427. "source": [
  428. "#看下图定义都有哪些操作,了解即可\n",
  429. "cube_func_int32.graph.get_operations()"
  430. ]
  431. },
  432. {
  433. "cell_type": "code",
  434. "execution_count": 20,
  435. "metadata": {
  436. "scrolled": true
  437. },
  438. "outputs": [
  439. {
  440. "name": "stdout",
  441. "output_type": "stream",
  442. "text": [
  443. "name: \"x\"\n",
  444. "op: \"Placeholder\"\n",
  445. "attr {\n",
  446. " key: \"_user_specified_name\"\n",
  447. " value {\n",
  448. " s: \"x\"\n",
  449. " }\n",
  450. "}\n",
  451. "attr {\n",
  452. " key: \"dtype\"\n",
  453. " value {\n",
  454. " type: DT_INT32\n",
  455. " }\n",
  456. "}\n",
  457. "attr {\n",
  458. " key: \"shape\"\n",
  459. " value {\n",
  460. " shape {\n",
  461. " dim {\n",
  462. " size: -1\n",
  463. " }\n",
  464. " }\n",
  465. " }\n",
  466. "}\n",
  467. "\n"
  468. ]
  469. }
  470. ],
  471. "source": [
  472. "pow_op = cube_func_int32.graph.get_operations()[0]\n",
  473. "print(pow_op)"
  474. ]
  475. },
  476. {
  477. "cell_type": "code",
  478. "execution_count": 12,
  479. "metadata": {},
  480. "outputs": [
  481. {
  482. "name": "stdout",
  483. "output_type": "stream",
  484. "text": [
  485. "[]\n",
  486. "--------------------------------------------------\n",
  487. "[<tf.Tensor 'z:0' shape=(None,) dtype=int32>]\n"
  488. ]
  489. }
  490. ],
  491. "source": [
  492. "print(list(pow_op.inputs))\n",
  493. "print('-'*50)\n",
  494. "print(list(pow_op.outputs))\n"
  495. ]
  496. },
  497. {
  498. "cell_type": "code",
  499. "execution_count": 13,
  500. "metadata": {},
  501. "outputs": [
  502. {
  503. "data": {
  504. "text/plain": [
  505. "<tf.Operation 'z' type=Placeholder>"
  506. ]
  507. },
  508. "execution_count": 13,
  509. "metadata": {},
  510. "output_type": "execute_result"
  511. }
  512. ],
  513. "source": [
  514. "#Placeholder用来放输入的地方,2.0中不需要,图中依然保留了\n",
  515. "cube_func_int32.graph.get_operation_by_name(\"z\")"
  516. ]
  517. },
  518. {
  519. "cell_type": "code",
  520. "execution_count": 16,
  521. "metadata": {},
  522. "outputs": [
  523. {
  524. "data": {
  525. "text/plain": [
  526. "<tf.Tensor 'z:0' shape=(None,) dtype=int32>"
  527. ]
  528. },
  529. "execution_count": 16,
  530. "metadata": {},
  531. "output_type": "execute_result"
  532. }
  533. ],
  534. "source": [
  535. "cube_func_int32.graph.get_tensor_by_name(\"z:0\")"
  536. ]
  537. },
  538. {
  539. "cell_type": "code",
  540. "execution_count": 34,
  541. "metadata": {},
  542. "outputs": [
  543. {
  544. "data": {
  545. "text/plain": [
  546. "node {\n",
  547. " name: \"z\"\n",
  548. " op: \"Placeholder\"\n",
  549. " attr {\n",
  550. " key: \"_user_specified_name\"\n",
  551. " value {\n",
  552. " s: \"z\"\n",
  553. " }\n",
  554. " }\n",
  555. " attr {\n",
  556. " key: \"dtype\"\n",
  557. " value {\n",
  558. " type: DT_INT32\n",
  559. " }\n",
  560. " }\n",
  561. " attr {\n",
  562. " key: \"shape\"\n",
  563. " value {\n",
  564. " shape {\n",
  565. " dim {\n",
  566. " size: -1\n",
  567. " }\n",
  568. " }\n",
  569. " }\n",
  570. " }\n",
  571. "}\n",
  572. "node {\n",
  573. " name: \"Pow/y\"\n",
  574. " op: \"Const\"\n",
  575. " attr {\n",
  576. " key: \"dtype\"\n",
  577. " value {\n",
  578. " type: DT_INT32\n",
  579. " }\n",
  580. " }\n",
  581. " attr {\n",
  582. " key: \"value\"\n",
  583. " value {\n",
  584. " tensor {\n",
  585. " dtype: DT_INT32\n",
  586. " tensor_shape {\n",
  587. " }\n",
  588. " int_val: 3\n",
  589. " }\n",
  590. " }\n",
  591. " }\n",
  592. "}\n",
  593. "node {\n",
  594. " name: \"Pow\"\n",
  595. " op: \"Pow\"\n",
  596. " input: \"z\"\n",
  597. " input: \"Pow/y\"\n",
  598. " attr {\n",
  599. " key: \"T\"\n",
  600. " value {\n",
  601. " type: DT_INT32\n",
  602. " }\n",
  603. " }\n",
  604. "}\n",
  605. "node {\n",
  606. " name: \"Identity\"\n",
  607. " op: \"Identity\"\n",
  608. " input: \"Pow\"\n",
  609. " attr {\n",
  610. " key: \"T\"\n",
  611. " value {\n",
  612. " type: DT_INT32\n",
  613. " }\n",
  614. " }\n",
  615. "}\n",
  616. "versions {\n",
  617. " producer: 175\n",
  618. "}"
  619. ]
  620. },
  621. "execution_count": 34,
  622. "metadata": {},
  623. "output_type": "execute_result"
  624. }
  625. ],
  626. "source": [
  627. "#打印出来看看图信息\n",
  628. "cube_func_int32.graph.as_graph_def()"
  629. ]
  630. },
  631. {
  632. "cell_type": "code",
  633. "execution_count": null,
  634. "metadata": {},
  635. "outputs": [],
  636. "source": []
  637. }
  638. ],
  639. "metadata": {
  640. "kernelspec": {
  641. "display_name": "Python 3",
  642. "language": "python",
  643. "name": "python3"
  644. },
  645. "language_info": {
  646. "codemirror_mode": {
  647. "name": "ipython",
  648. "version": 3
  649. },
  650. "file_extension": ".py",
  651. "mimetype": "text/x-python",
  652. "name": "python",
  653. "nbconvert_exporter": "python",
  654. "pygments_lexer": "ipython3",
  655. "version": "3.6.9"
  656. }
  657. },
  658. "nbformat": 4,
  659. "nbformat_minor": 2
  660. }

随着人工智能和大数据的发展,任一方面对自动化工具有着一定的需求,在当下疫情防控期间,使用mindspore来实现yolo模型来进行目标检测及语义分割,对视频或图片都可以进行口罩佩戴检测和行人社交距离检测,来对公共场所的疫情防控来实行自动化管理。