TinyML4.3.2 生成数据(Create Sin)

最近在学习TinyML,但书本上的教程是在Google的Colab云平台上开发,由于国内不能访问Colab,手上刚好有一个Jetbot (Jeston Nano),所以就基于Jetbot进行开发。

浏览器访问ip(oled上显示的ip地址):8888,如192.168.10107:8888,Password:jetbot。

TinyML4.3.2 生成数据(Create Sin)_第1张图片

双击Notebool下的Python 3,然后编辑代码:

import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
import math

#We'll generate this many sample datapoints
SAMPLES = 1000

#Set a "seed" value, so we get the same random numbers each time we run this 
#notebook. Any number can be used here.
SEED = 1337

np.random.seed(SEED)
tf.random.set_random_seed(SEED)

#Generate a uniformly distributed set of random numbers in the range from
#0 to 2n, which covers a complete sine wave oscillation
x_values = np.random.uniform(low=0, high=2*math.pi, size=SAMPLES)

#Shuffle the values to guarantee they're not in orders
np.random.shuffle(x_values)

#Calculate the corresponding sine values
y_values = np.sin(x_values)

#plot our data. The 'b.' argument tells the library to print blue dots.
plt.plot(x_values, y_values, 'b.')
plt.show()

 然后运行,显示如下:

TinyML4.3.2 生成数据(Create Sin)_第2张图片

加入噪声 

在np.random.shuffle(x_values)语句之后增加以下代码:

#Add a small random number to each y value
y_values += 0.1 * np.random.randn(*y_values.shape)

然后运行,显示如下:

TinyML4.3.2 生成数据(Create Sin)_第3张图片

注意:

jetbot没有matplotlib.pyplot库,需要使用terminal安装。

TinyML4.3.2 生成数据(Create Sin)_第4张图片

 双击Other下的Terminal,然后执行如下命令安装matplotlib.pyplot:

#apt-get
#apt-get install python3-matplotlib

你可能感兴趣的:(AI学习,TinyML,Jetson,nano,sin)