在TensorFlow中,对于图像,如何将圆外的值设置为零?

时间:2018-10-06 21:36:17

标签: tensorflow

我想做的就是这样。

enter image description here enter image description here

下面是使用numpy的代码。如何使用张量流功能做到这一点?

@Singleton
@Startup
public class PreapreTaskRunningAsync {

    @EJB
    MyAsyncEJB myAsyncEJB;

    @Lock(LockType.READ)
    public void startTask(){
        myAsyncEJB.getSomethingAsyc(new CallBackFuture());
    }

    final class CallBackFuture implements CallBack<String>{

        @Override
        public void oncomplete(Throwable t, String result) {
            if ( t != null ) {
                t.printStackTrace();
                System.out.println("Exception! " + result);
            }
            System.out.println(result);
        }



    }

    interface CallBack<T> {
        void oncomplete(Throwable t, T result);
    } 

@Stateless
public class MyAsyncEJB {


    @Asynchronous
    public void getSomethingAsyc(PreapreTaskRunningAsync.CallBackFuture stringCallBackFuture){
        try {
            Thread.sleep(3000);
            stringCallBackFuture.oncomplete(null, "DONE!");
        } catch (InterruptedException e) {
            e.printStackTrace();
            stringCallBackFuture.oncomplete(e, "ERROR!");
        }
    }
}

1 个答案:

答案 0 :(得分:0)

您可以通过将图像张量与蒙版张量相乘来实现。遮罩张量应为带有1.内圆和0.外侧的张量。您可以使用占位符传递此蒙版,或者如果所有图像的大小都是固定的,则可以将该张量定义为tf.constant。