diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 86be92d9ad90d7fcf732a94960e02ef2ede0a5e1..b037834b648411da1489ad24f1366fbd63348452 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -10,6 +10,7 @@ variables: DOCKER_DRIVER: overlay2 CACHE_IMAGE_BASE: $CI_REGISTRY_IMAGE:otbtf-base CACHE_IMAGE_BUILDER: $CI_REGISTRY_IMAGE:builder + BRANCH_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME workflow: rules: @@ -44,6 +45,7 @@ docker image: --build-arg BASE_IMG="ubuntu:20.04" --build-arg BUILDKIT_INLINE_CACHE=1 "." + - docker push $CACHE_IMAGE_BASE - > docker build --target builder @@ -57,24 +59,22 @@ docker image: --build-arg BASE_IMG="ubuntu:20.04" --build-arg BUILDKIT_INLINE_CACHE=1 "." + - docker push $CACHE_IMAGE_BUILDER - > docker build --network="host" --cache-from $CACHE_IMAGE_BASE --cache-from $CACHE_IMAGE_BUILDER - --cache-from $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME + --cache-from $BRANCH_IMAGE --cache-from $CI_REGISTRY_IMAGE:cpu-basic-dev-testing - --tag $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME + --tag $BRANCH_IMAGE --build-arg OTBTESTS="true" --build-arg KEEP_SRC_OTB="true" --build-arg BZL_CONFIGS="" --build-arg BASE_IMG="ubuntu:20.04" --build-arg BUILDKIT_INLINE_CACHE=1 "." - after_script: - - docker push $CACHE_IMAGE_BASE - - docker push $CACHE_IMAGE_BUILDER - - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME + - docker push $BRANCH_IMAGE .static_analysis_base: stage: Static Analysis @@ -160,8 +160,8 @@ deploy: timeout: 10 hours script: - echo "Shippping!" - - docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME - - docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME $CI_REGISTRY_IMAGE:cpu-basic-dev-testing + - docker pull $BRANCH_IMAGE + - docker tag $BRANCH_IMAGE $CI_REGISTRY_IMAGE:cpu-basic-dev-testing - docker push $CI_REGISTRY_IMAGE:cpu-basic-dev-testing - docker build --network='host' --tag $CI_REGISTRY_IMAGE:cpu-basic --build-arg BASE_IMG=ubuntu:20.04 --build-arg BZL_CONFIGS="" . # cpu-basic - docker push $CI_REGISTRY_IMAGE:cpu-basic diff --git a/Dockerfile b/Dockerfile index d5a644f7bcc1c16251ba27b887eca984608339fb..da634cea3fb7dbbce68b3660b9900e2d60a0d837 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,7 +25,8 @@ RUN if $GUI; then \ RUN ln -s /usr/bin/python3 /usr/local/bin/python && ln -s /usr/bin/pip3 /usr/local/bin/pip # NumPy version is conflicting with system's gdal dep and may require venv ARG NUMPY_SPEC="==1.22.*" -RUN pip install --no-cache-dir -U pip wheel mock six future tqdm deprecated "numpy$NUMPY_SPEC" \ +ARG PROTO_SPEC="==3.20.*" +RUN pip install --no-cache-dir -U pip wheel mock six future tqdm deprecated "numpy$NUMPY_SPEC" "protobuf$PROTO_SPEC" \ && pip install --no-cache-dir --no-deps keras_applications keras_preprocessing # ---------------------------------------------------------------------------- diff --git a/include/otbTensorflowSampler.hxx b/include/otbTensorflowSampler.hxx index 966a37969c43ffdb9b7df32ea21dc8a0c7330dd2..323cdfbe455dff56bbe6ff1e062524be9bf691bb 100644 --- a/include/otbTensorflowSampler.hxx +++ b/include/otbTensorflowSampler.hxx @@ -179,57 +179,60 @@ TensorflowSampler<TInputImage, TVectorData>::Update() if (!itVector.Get()->IsRoot() && !itVector.Get()->IsDocument() && !itVector.Get()->IsFolder()) { DataNodePointer currentGeometry = itVector.Get(); - PointType point = currentGeometry->GetPoint(); - - // Get the label value - labelPix[0] = static_cast<InternalPixelType>(currentGeometry->GetFieldAsInt(m_Field)); - - bool hasBeenSampled = true; - for (unsigned int i = 0; i < nbInputs; i++) + if (currentGeometry->HasField(m_Field)) { - // Get input - ImagePointerType inputPtr = const_cast<ImageType *>(this->GetInput(i)); + PointType point = currentGeometry->GetPoint(); - // Try to sample the image - if (!tf::SampleImage<ImageType>(inputPtr, m_OutputPatchImages[i], point, count, m_PatchSizes[i])) - { - // If not, reject this sample - hasBeenSampled = false; - } - // If NoData is provided, check if the sampled patch contains a no-data value - if (m_NoDataValues.count(i) > 0 && hasBeenSampled) + // Get the label value + labelPix[0] = static_cast<InternalPixelType>(currentGeometry->GetFieldAsInt(m_Field)); + + bool hasBeenSampled = true; + for (unsigned int i = 0; i < nbInputs; i++) { - IndexType outIndex; - outIndex[0] = 0; - outIndex[1] = count * m_PatchSizes[i][1]; - RegionType region(outIndex, m_PatchSizes[i]); + // Get input + ImagePointerType inputPtr = const_cast<ImageType *>(this->GetInput(i)); - IteratorType it(m_OutputPatchImages[i], region); - for (it.GoToBegin(); !it.IsAtEnd(); ++it) + // Try to sample the image + if (!tf::SampleImage<ImageType>(inputPtr, m_OutputPatchImages[i], point, count, m_PatchSizes[i])) + { + // If not, reject this sample + hasBeenSampled = false; + } + // If NoData is provided, check if the sampled patch contains a no-data value + if (m_NoDataValues.count(i) > 0 && hasBeenSampled) { - PixelType pix = it.Get(); - for (unsigned int band = 0; band < pix.Size(); band++) - if (pix[band] == m_NoDataValues[i]) - hasBeenSampled = false; + IndexType outIndex; + outIndex[0] = 0; + outIndex[1] = count * m_PatchSizes[i][1]; + RegionType region(outIndex, m_PatchSizes[i]); + + IteratorType it(m_OutputPatchImages[i], region); + for (it.GoToBegin(); !it.IsAtEnd(); ++it) + { + PixelType pix = it.Get(); + for (unsigned int band = 0; band < pix.Size(); band++) + if (pix[band] == m_NoDataValues[i]) + hasBeenSampled = false; + } } + } // Next input + if (hasBeenSampled) + { + // Fill label + labelIndex[1] = count; + m_OutputLabelImage->SetPixel(labelIndex, labelPix); + + // update count + count++; + } + else + { + rejected++; } - } // Next input - if (hasBeenSampled) - { - // Fill label - labelIndex[1] = count; - m_OutputLabelImage->SetPixel(labelIndex, labelPix); - // update count - count++; + // Update progress + progress.CompletedPixel(); } - else - { - rejected++; - } - - // Update progress - progress.CompletedPixel(); } ++itVector;