Guest User

Untitled

a guest
Oct 15th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. set json = '''{}''';
  2. load jsonStr.`json` as emptyData;
  3.  
  4. run emptyData as ImageLoaderExt.`/Users/allwefantasy/Downloads/cifar/train`
  5. where numOfImageTasks="4"
  6. and code='''
  7. def apply(params:Map[String,String]) = {
  8. Resize(28, 28) ->
  9. MatToTensor() -> ImageFrameToSample()
  10. }
  11. '''
  12. as data;
  13.  
  14. select split(split(imageName,"_")[1],"\\.")[0] as labelStr,features from data as newdata;
  15.  
  16. train newdata as StringIndex.`/tmp/si` where inputCol="labelStr" and outputCol="labelIndex" as newdata1;
  17. predict newdata as StringIndex.`/tmp/si` as newdata2;
  18.  
  19. select (cast(labelIndex as int) + 1) as label,features from newdata2 as newdata3;
  20.  
  21. save overwrite newdata3 as parquet.`/tmp/cifar_train_data`;
  22.  
  23. load parquet.`/tmp/cifar_train_data` as newdata3;
  24. select array(cast(label as float)) as label,features from newdata3 as newdata4;
  25. -- select * from newdata4 limit 1 as output;
  26.  
  27. train newdata4 as BigDLClassifyExt.`/tmp/bigdl` where
  28. fitParam.0.featureSize="[3,28,28]"
  29. and fitParam.0.classNum="10"
  30. and fitParam.0.maxEpoch="50"
  31. and fitParam.0.code='''
  32. def apply(params:Map[String,String])={
  33. val model = Sequential()
  34. model.add(Reshape(Array(3, 28, 28), inputShape = Shape(28, 28, 3)))
  35. model.add(Convolution2D(6, 5, 5, activation = "tanh").setName("conv1_5x5"))
  36. model.add(MaxPooling2D())
  37. model.add(Convolution2D(12, 5, 5, activation = "tanh").setName("conv2_5x5"))
  38. model.add(MaxPooling2D())
  39. model.add(Flatten())
  40. model.add(Dense(100, activation = "tanh").setName("fc1"))
  41. model.add(Dense(params("classNum").toInt, activation = "softmax").setName("fc2"))
  42. }
  43.  
  44. '''
  45. ;
  46. predict newdata4 as BigDLClassifyExt.`/tmp/bigdl` as predictdata;
  47.  
  48.  
  49. -- register BigDLClassifyExt.`/tmp/bigdl` as mnistPredict;
  50.  
  51. -- select
  52. -- vec_argmax(mnistPredict(vec_dense(features))) as predict_label,
  53. -- label from data
  54. -- as output;
Add Comment
Please, Sign In to add comment