In the default example app whenever you create new fultter project I just added the following code.
initState() {
super.initState();
loop();
}
loop() async {
while (true) {
await Future.delayed(Duration(milliseconds: 10));
print("count now:$_counter");
}
}
Run Code Online (Sandbox Code Playgroud)
Why is the app UI is not getting blocked? I am able to click + button and the counter increases smoothly. Even if I change the delay to 10 sec, the UI is resposive. Is the loop() runnning in different thread?but I know dart is …
我正在使用该batch(8)函数,它修改形状并添加批次尺寸,但每批次仅获取一张图像。下面是我的代码:-
import cv2
import numpy as np
import os
import tensorflow as tf
import random
folder_path = "./real/"
files = os.listdir(folder_path)
def get_image():
index = random.randint(0,len(files)-1)
img = cv2.imread(folder_path+files[index])
img = cv2.resize(img,(128,128))
img = img/255.
#More complex transformation
yield img
dset = tf.data.Dataset.from_generator(get_image,(tf.float32)).batch(8)
for img in dset:
print(img.shape)
break
Run Code Online (Sandbox Code Playgroud)
即使使用batch(8),输出仍然是(1, 128, 128, 3)。我是否需要修改生成器来手动创建批次?另外,如何将其包装在tensorflow中的生成器中,使其运行得更快?