diff --git a/pysegcnn/core/utils.py b/pysegcnn/core/utils.py
index 3a5ee0b69c5b73687215ebaf51464dba71d2ac2e..8da06b68270b2503125611d0960a42ef810af343 100644
--- a/pysegcnn/core/utils.py
+++ b/pysegcnn/core/utils.py
@@ -365,31 +365,35 @@ def hdf2tifs(path, outpath=None, overwrite=False, create_stack=True, **kwargs):
     # read the hdf dataset
     hdf = gdal.Open(str(path)).GetSubDatasets()
 
-    # iterate over the different subdatasets in the hdf
-    for ds in hdf:
+    # check if the dataset is not empty
+    if hdf:
 
-        # name of the current subdataset
-        name = ds[0].split(':')[-1]
+        # iterate over the different subdatasets in the hdf
+        for ds in hdf:
+
+            # name of the current subdataset
+            name = ds[0].split(':')[-1]
 
-        # filename of the GeoTIFF
-        tif_name = outpath.joinpath(path.name.replace(path.suffix,
-                                                      '_{}.tif'.format(name)))
+            # filename of the GeoTIFF
+            tif_name = outpath.joinpath(
+                path.name.replace(path.suffix, '_{}.tif'.format(name)))
 
-        # convert hdf subdataset to GeoTIFF
-        gdal.Translate(str(tif_name), gdal.Open(ds[0]), **kwargs)
+            # convert hdf subdataset to GeoTIFF
+            gdal.Translate(str(tif_name), gdal.Open(ds[0]), **kwargs)
 
-    # check whether to create a GeoTIFF stack
-    if create_stack:
-        # filename for the GeoTIFF stack
-        stk = tif_name.parent.joinpath(path.name.replace(path.suffix, '.tif'))
-        LOGGER.info('Creating GeoTIFF stack: {}'.format(stk))
+        # check whether to create a GeoTIFF stack
+        if create_stack:
+            # filename for the GeoTIFF stack
+            stk = tif_name.parent.joinpath(
+                path.name.replace(path.suffix, '.tif'))
+            LOGGER.info('Creating GeoTIFF stack: {}'.format(stk))
 
-        # generated GeoTIFF files
-        tifs = [str(f) for f in outpath.iterdir() if f.suffix in
-                ['.tif', '.TIF']]
+            # generated GeoTIFF files
+            tifs = [str(f) for f in outpath.iterdir() if f.suffix in
+                    ['.tif', '.TIF']]
 
-        # create stacked GeoTIFF
-        stack_tifs(str(stk), tifs)
+            # create stacked GeoTIFF
+            stack_tifs(str(stk), tifs)
 
     return