from_generator застрял в tf1.15.2

#python #tensorflow #tensorflow-datasets

Вопрос:

Я использую среду Colab для запуска Dataset.from_generator для создания набора данных (у каждого образца есть изображение и метка). Он печатает первые три образца, но это занимает 30 минут и все еще не получает следующий образец (все еще загружается), и я не могу понять, почему, может ли кто-нибудь из вас, пожалуйста, помочь мне с моей проблемой. Вот как я создаю его с помощью input_function.

 def input_fn_real_test(test_list, batch_size = 1, epoch = 1, padding_info = None):
    def input_fn():
        def input_fn_handle():
            print("generate dataset")
            input_fn_gen = input_fn_generator_test(test_list)
            print("done generation")
            return input_fn_gen
        print("done input function", input_fn_handle)
        ds=Dataset.from_generator(input_fn_handle, 
                     (tf.string, tf.int32)
                     )
        print("done create dataset")
        if (flags.paras.prefetch>1):
            ds=ds.prefetch(flags.paras.prefetch)
        ds=ds.map(real_parser_fun, num_parallel_calls=20)
        if (padding_info):
            ds.padded_batch(batch_size, padded_shapes=padding_info)
        else:
            ds=ds.batch(batch_size)
        ds=ds.repeat(epoch)
        
        value = ds.make_one_shot_iterator().get_next()
        print("get value from iteration", value)
        return value
    return input_fn
 

Это мой входной генератор

 def input_fn_generator_test(test_list):
    FILES_LIST=[]
    for fInd in range(len(test_list)):
        path_train_file=test_list[fInd]
        FILES=glob.glob(os.path.join(path_train_file[1],'*'))
        FILES_LIST=FILES_LIST FILES
    FILES_LIST = pick_real_video(FILES_LIST)
    for i in range(len(FILES_LIST)):
        path_image=FILES_LIST[i]
        print("path", path_image)
        # print(i,name_pure)
        label = FILES_LIST[i].split("/")[-2]
        print(label)
        text = 1 if label == "real" else 0
        ALLDATA=[str(path_image), text ]
        print("data", ALLDATA)
        yield tuple(ALLDATA)
 

это мой основной код

 if __name__=='__main__':
    train_list=[flags.path.real_test_file]

    def input_fn_handle():
        return input_fn_generator_test(train_list)
    ds=Dataset.from_generator(input_fn_handle, 
                     (tf.string, tf.string)
                     )
    
    ds=input_fn_real_test(train_list)
    value=ds()
    #value = ds().make_one_shot_iterator().get_next()
    with tf.Session() as sess:
        start=datetime.datetime.now()  
        #for x in range(100):
        x = 0
        while True:
            val_, names_=sess.run( [value['images'], value['labels'] ]) 
            print(x, val_.shape, names_.decode())

            val_ = val_[0,:,:,0:3]            
            image = val_   127.5
            image = np.squeeze(image)
            image = np.array(image, dtype = np.uint8)
            image_pil = Image.fromarray(image)
            if True:#name_pure.split('_')[-1] == '1':
                image_pil.save('./tmp/%d_image.bmp'%(x))
                # depth_pil.save('./tmp/%d_maps.bmp'%(x))
            

            lucky=1   
            x  = 1
        end=datetime.datetime.now() 
        print('Time consuming:', (end-start).seconds )
    
    lucky=1
 

And here is my log for running the code. U can see it just read three path in my dataset folder.

 done input function <function input_fn_real_test.<locals>.input_fn.<locals>.input_fn_handle at 0x7f17eb026ef0>
done create dataset
WARNING:tensorflow:Entity <function real_parser_fun at 0x7f17eb026200> could not be transformed and will be executed as-is. Please report this to the AutoGraph team. When filing the bug, set the verbosity to 10 (on Linux, `export AUTOGRAPH_VERBOSITY=10`) and attach the full output. Cause: module 'gast' has no attribute 'Index'
WARNING:tensorflow:From /content/fas_sgtd_multi_frame/generate_data_test.py:277: py_func (from tensorflow.python.ops.script_ops) is deprecated and will be removed in a future version.
Instructions for updating:
tf.py_func is deprecated in TF V2. Instead, there are two
    options available in V2.
    - tf.py_function takes a python function which manipulates tf eager
    tensors instead of numpy arrays. It's easy to convert a tf eager tensor to
    an ndarray (just call tensor.numpy()) but having access to eager tensors
    means `tf.py_function`s can use accelerators such as GPUs as well as
    being differentiable using a gradient tape.
    - tf.numpy_function maintains the semantics of the deprecated tf.py_func
    (it is not differentiable, and manipulates numpy arrays). It drops the
    stateful argument making all functions stateful.
    
features images Tensor("truediv:0", shape=(256, 256, 15), dtype=float32)
WARNING:tensorflow:From /content/fas_sgtd_multi_frame/generate_data_test.py:340: DatasetV1.make_one_shot_iterator (from tensorflow.python.data.ops.dataset_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use `for ... in dataset:` to iterate over a dataset. If using `tf.estimator`, return the `Dataset` object directly from your input function. As a last resort, you can use `tf.compat.v1.data.make_one_shot_iterator(dataset)`.
get value from iteration {'images': <tf.Tensor 'IteratorGetNext:0' shape=(?, 256, 256, 15) dtype=float32>, 'labels': <tf.Tensor 'IteratorGetNext:1' shape=(?, 1) dtype=int32>}
WARNING:tensorflow:From /content/fas_sgtd_multi_frame/generate_data_test.py:377: The name tf.Session is deprecated. Please use tf.compat.v1.Session instead.

2021-10-12 03:55:25.393900: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcuda.so.1
2021-10-12 03:55:25.410234: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:983] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-10-12 03:55:25.411257: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1639] Found device 0 with properties: 
name: Tesla P100-PCIE-16GB major: 6 minor: 0 memoryClockRate(GHz): 1.3285
pciBusID: 0000:00:04.0
2021-10-12 03:55:25.411527: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.1
2021-10-12 03:55:25.413263: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcublas.so.10
2021-10-12 03:55:25.414661: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcufft.so.10
2021-10-12 03:55:25.415229: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcurand.so.10
2021-10-12 03:55:25.417118: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusolver.so.10
2021-10-12 03:55:25.418199: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusparse.so.10
2021-10-12 03:55:25.422716: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudnn.so.7
2021-10-12 03:55:25.422829: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:983] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-10-12 03:55:25.423829: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:983] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-10-12 03:55:25.424682: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1767] Adding visible gpu devices: 0
2021-10-12 03:55:25.430093: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 2199995000 Hz
2021-10-12 03:55:25.430335: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x5625d1985100 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2021-10-12 03:55:25.430372: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
2021-10-12 03:55:25.628840: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:983] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-10-12 03:55:25.630065: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x5625d19852c0 initialized for platform CUDA (this does not guarantee that XLA will be used). Devices:
2021-10-12 03:55:25.630103: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Tesla P100-PCIE-16GB, Compute Capability 6.0
2021-10-12 03:55:25.630312: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:983] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-10-12 03:55:25.631197: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1639] Found device 0 with properties: 
name: Tesla P100-PCIE-16GB major: 6 minor: 0 memoryClockRate(GHz): 1.3285
pciBusID: 0000:00:04.0
2021-10-12 03:55:25.631295: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.1
2021-10-12 03:55:25.631348: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcublas.so.10
2021-10-12 03:55:25.631410: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcufft.so.10
2021-10-12 03:55:25.631473: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcurand.so.10
2021-10-12 03:55:25.631517: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusolver.so.10
2021-10-12 03:55:25.631573: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusparse.so.10
2021-10-12 03:55:25.631614: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudnn.so.7
2021-10-12 03:55:25.631717: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:983] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-10-12 03:55:25.632664: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:983] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-10-12 03:55:25.633557: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1767] Adding visible gpu devices: 0
2021-10-12 03:55:25.633643: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.1
2021-10-12 03:55:25.635457: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1180] Device interconnect StreamExecutor with strength 1 edge matrix:
2021-10-12 03:55:25.635491: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1186]      0 
2021-10-12 03:55:25.635509: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1199] 0:   N 
2021-10-12 03:55:25.635655: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:983] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-10-12 03:55:25.636650: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:983] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-10-12 03:55:25.637684: W tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:39] Overriding allow_growth setting because the TF_FORCE_GPU_ALLOW_GROWTH environment variable is set. Original config value was 0.
2021-10-12 03:55:25.637741: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1325] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 15224 MB memory) -> physical GPU (device: 0, name: Tesla P100-PCIE-16GB, pci bus id: 0000:00:04.0, compute capability: 6.0)
generate dataset
done generation
Pick real video :
----------------------------------------
Real Counts: 1743
----------------------------------------
path /content/fas_sgtd_multi_frame/test/real/0002_01_00_01_150.jpg
real
data ['/content/fas_sgtd_multi_frame/test/real/0002_01_00_01_150.jpg', 1]
path /content/fas_sgtd_multi_frame/test/real/0006_00_00_02_393.jpg
real
data ['/content/fas_sgtd_multi_frame/test/real/0006_00_00_02_393.jpg', 1]
WARNING:tensorflow:From /tensorflow-1.15.2/python3.7/tensorflow_core/python/ops/resource_variable_ops.py:1630: calling BaseResourceVariable.__init__ (from tensorflow.python.ops.resource_variable_ops) with constraint is deprecated and will be removed in a future version.
Instructions for updating:
If using Keras pass *_constraint arguments to layers.
2021-10-12 03:55:27.079286: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:983] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-10-12 03:55:27.080452: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1639] Found device 0 with properties: 
name: Tesla P100-PCIE-16GB major: 6 minor: 0 memoryClockRate(GHz): 1.3285
pciBusID: 0000:00:04.0
2021-10-12 03:55:27.080631: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.1
2021-10-12 03:55:27.080686: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcublas.so.10
2021-10-12 03:55:27.080739: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcufft.so.10
2021-10-12 03:55:27.080787: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcurand.so.10
2021-10-12 03:55:27.080844: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusolver.so.10
2021-10-12 03:55:27.080895: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusparse.so.10
2021-10-12 03:55:27.080947: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudnn.so.7
2021-10-12 03:55:27.081058: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:983] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-10-12 03:55:27.082216: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:983] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-10-12 03:55:27.083220: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1767] Adding visible gpu devices: 0
2021-10-12 03:55:27.083292: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1180] Device interconnect StreamExecutor with strength 1 edge matrix:
2021-10-12 03:55:27.083321: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1186]      0 
2021-10-12 03:55:27.083342: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1199] 0:   N 
2021-10-12 03:55:27.083508: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:983] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-10-12 03:55:27.084722: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:983] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-10-12 03:55:27.085859: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1325] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 15224 MB memory) -> physical GPU (device: 0, name: Tesla P100-PCIE-16GB, pci bus id: 0000:00:04.0, compute capability: 6.0)
2021-10-12 03:55:27.093508: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:983] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-10-12 03:55:27.094555: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1639] Found device 0 with properties: 
name: Tesla P100-PCIE-16GB major: 6 minor: 0 memoryClockRate(GHz): 1.3285
pciBusID: 0000:00:04.0
2021-10-12 03:55:27.094630: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.1
2021-10-12 03:55:27.094706: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcublas.so.10
2021-10-12 03:55:27.094762: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcufft.so.10
2021-10-12 03:55:27.094824: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcurand.so.10
2021-10-12 03:55:27.094876: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusolver.so.10
2021-10-12 03:55:27.094926: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusparse.so.10
2021-10-12 03:55:27.094976: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudnn.so.7
2021-10-12 03:55:27.095120: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:983] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-10-12 03:55:27.096260: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:983] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-10-12 03:55:27.097284: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1767] Adding visible gpu devices: 0
2021-10-12 03:55:27.097339: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1180] Device interconnect StreamExecutor with strength 1 edge matrix:
2021-10-12 03:55:27.097371: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1186]      0 
2021-10-12 03:55:27.097412: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1199] 0:   N 
2021-10-12 03:55:27.097575: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:983] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-10-12 03:55:27.098807: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:983] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-10-12 03:55:27.099972: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1325] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 15224 MB memory) -> physical GPU (device: 0, name: Tesla P100-PCIE-16GB, pci bus id: 0000:00:04.0, compute capability: 6.0)