2020년 10월 20일 화요일

To set gpu memory rate manually when using keras

from tensorflow.compat.v1 import ConfigProto
from tensorflow.compat.v1 import InteractiveSession
config = ConfigProto()
config.gpu_options.per_process_gpu_memory_fraction = 0.8
session = InteractiveSession(config=config)

tensorflow.python.framework.errors_impl.UnknownError: Failed to get convolution algorithm. This is probably because cuDNN failed to initialize

add this code below on the top of the source code

gpus = tf.config.experimental.list_physical_devices('GPU')
if gpus:
try:
# Currently, memory growth needs to be the same across GPUs
for gpu in gpus:
tf.config.experimental.set_memory_growth(gpu, True)
logical_gpus = tf.config.experimental.list_logical_devices('GPU')
print(len(gpus), "Physical GPUs,", len(logical_gpus), "Logical GPUs")
except RuntimeError as e:
# Memory growth must be set before GPUs have been initialized
print(e)






2020년 10월 16일 금요일

After removing storyboard, app appears black in iOS with Objective-c.

1. set iOS version over 13 and make "Main Interface" is empty

2. add a ViewController

3. nd code below in the SceneDelegate.m 

- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {

    // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.

    // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.

    // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).

    

    self.window = [[UIWindow alloc] initWithWindowScene:(UIWindowScene*)scene];

    MainViewController *controller = [[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil];

    self.window.backgroundColor = [UIColor redColor];

    self.window.rootViewController = controller;

    [self.window makeKeyAndVisible];

}

2020년 9월 8일 화요일

Print whole matrix in Numpy

import sys

import numpy as np

np.set_printoptions(threshold=sys.maxsize)

// and then print the matrix what you want

print(np.arange(1000).reshape(2,5,100))

2020년 8월 3일 월요일

[Android] Google Social Login

build-generate signed bundle/APK.. 메뉴에서 서명키 생성 
xxxx.jks 파일 위치 확인

release 용 sha1 확인
keytool -keystore goodbulter_keystore.jks -list -v

Firebase 키 추가
1. 이동 https://console.firebase.google.com/?hl=ko
2. 프로젝트 선택
3. 프로젝트개요 톱니바퀴-프로젝트 설정
4. 내앱 카테고리에서 sha1 디지털 지문 추가
5. google-services.json 다운로드
6. 안드로이드 스튜디오 프로젝트 브라우저에서 project로 바꿈
7. app 폴더 밑에 josn 파일 복사(끌어다 놓기)
8. 메뉴 build-generate signed bundle/APK.. 
9. 빌드 후 구글 플레이 콘솔사이트 이동
10. 출시관리-앱버전 => 버전수정->빌드된 파일추가(aac or apk)
11. 맨아래 버전 코멘트 
12. 검토->게시

2020년 7월 27일 월요일

Using Swift framework in an Objective-c project

reference
https://marcinczenko.github.io/post/using-swift-frameworks-from-objective-c-target/


===============================================
=============== Swift Framework ===============
===============================================
Make a ExampleSwiftFramework framework. not Static Library
Add ExampleSwiftFramework.swift and put the code below

@objc
public class ExampleSwiftFrameworkClass : NSObject {

    let message: String

    @objc(init:)
    public init(withHelloMessage message: String) {
        self.message = message
    }

    @objc(sayHello)
    public func sayHello() -> String {
        return self.message
    }
}

TARGETS->Build Settings
Mach-O : 'Dynamic Library'

Build Options->Always Embeded Swift Standard Libraries : No
Packaging->Defines Module : Yes
Apple Clang-Language-Modules->Enable Modules(C and Objective-C) : Yes

next to the upper left 'stop' icon. click framework and edit scheme->Run->Build Configuration=> Release

Click Product->Build
and you can see the built framework on the project navigato.
Right click at the file->Show in Finder

===============================================
============= Objective-C project =============
===============================================
Make an objective-C project

TARGETS->General
1. add the swift framework into the 'Frameworks, Libraries, and Embedded Content'
2. and then you can see 'Framework' folder in the project navigator.
3. remove the framework from the 'Frameworks, Libraries, and Embedded Content'
4. drag the framework.framework folder into the 'Framework' in the project navigator

TARGETS -> Build Settings(All, Combined taps)
Build Option -> Always Embed Swift Standard Libraries : No

TARGETS -> Build Phases
Click '+' and add New Copy Files Phase category
add the swift framework what you need and keep the default option(Code Sign On Copy : checked, Copy only when installing : unchecked)

put the code below in -(void)viewDidLoad

ExampleSwiftFrameworkClass *exam = [[ExampleSwiftFrameworkClass alloc] init:@"Test"];
NSLog(@"%@", [exam sayHello]);

2020년 7월 19일 일요일

Room migrations in Kotlin

To test you need two class 

//===============================================================
// AppDatabase class
Database(entities = [Song::class], version = 1, exportSchema = false)
abstract class AppDatabase : RoomDatabase() {
        companion object {
        @Volatile private var INSTANCE: AppDatabase? = null
        fun getInstance(context: Context): AppDatabase =
            INSTANCE ?: synchronized(this) {                
         INSTANCE ?: buildDatabase(context).also {INSTANCE = it }}
        private fun buildDatabase(context: Context) =              
        Room.databaseBuilder(context.applicationContext,                  
        AppDatabase::class.java, "test.db").build()
        fun destroyInstance() {
            INSTANCE = null        
        }
    }
}

//===============================================================
// Entity class
// when the version was 1
@Entitydata class Song(
    @PrimaryKey val id: Long,    val title: String
)
//===============================================================


When you run an app with the database version 1
after then you modified the Song class added 'tag' entity.
@Entitydata class Song(
    @PrimaryKey    val id: Long,    
    val title: String,    
    val tag: String // Added in version 2.
)
you should change the version number of AppDatabase class like below from 1 to 2
Database(entities = [Song::class], version = 2, exportSchema = false)

you also have to edit database builder like this

private fun buildDatabase(context: Context) =
     Room.databaseBuilder(context.applicationContext, 
          AppDatabase::class.java, "terry.db")
          .addMigrations(MIGRATION_1_2).build()

and add migration code or edit it in the Song class
// Migration from 1 to 2, Room 2.1.0val MIGRATION_1_2 = object : Migration(1, 2) {
    override fun migrate(database: SupportSQLiteDatabase) {
        database.execSQL(
            "ALTER TABLE Song ADD COLUMN tag TEXT NOT NULL DEFAULT ''")
    }
}

That's all! :)